Python - Assigning vertex weights is extremely slow Current very slow method (code reduced):
    obj = bpy.context.active_object
    vgroups = obj.vertex_groups.new(name=&quot;test_layer&quot;)

    for loop in obj.data.loops:
        vindex = obj.data.loops[loop.index].vertex_index
        vgroups.add([vindex], value, &quot;REPLACE&quot;)

Performance is tested on 1024 x 1024 grid and takes minutes to complete for several weight layers.
My goal is not to assign the same weight value, but different values for each vertex.
I believe I am looking for something like below, which does not exist.
active_object.vertex_groups[group_name].foreach_set()
Usage of loops here is not clear.
You can:
import bpy

obj = bpy.context.active_object
vgroup = obj.vertex_groups.new(name=&quot;test_layer&quot;)

value = 0.5

for i in range(len(obj.data.vertices)):
    vgroup.add( [i], value, 'REPLACE')

We add vertices to a group, using their indexes.
The documentation is here:

add(index, weight, type)
Add vertices to the group

Parameters
        index (int array of 1 items in [-inf, inf]) – Index List
        weight (float in [0, 1]) – Vertex weight
        type (enum in ['REPLACE', 'ADD', 'SUBTRACT']) –
        Vertex assign mode
            REPLACE Replace, Replace.
            ADD Add, Add.
            SUBTRACT Subtract, Subtract.