Why is my script to add large batches of objects so slow? v2.90 I have to create about 30,000 spheres and I notice that even adding a 1000 is already a lot of work for Blender. I've cut down (hopefully?) on work and memory usage by creating just 1 mesh and 1 material for the batch, but I'd like blender to remain responsive during the batch job. Is there a way to update the UI, or an all together more recommended way of adding such a large number of objects? I will need to individually animate them.
# Creates a collection to store all the objects in.
collection = create_collection(scaffold, name)
mat = bpy.data.materials.new(name=name)
mat.diffuse_color = (1, 0, 0, 1)
# Creates an icosphere mesh
mesh = _create_ico_mesh(scaffold, name, radius)
for cell in cells:
    cell.object = obj = bpy.data.objects.new(name=f&quot;{name} #{cell.id}&quot;, object_data=mesh)
    obj.location = cell.position
    obj.data.materials.append(mat)
    collection.objects.link(obj)

Even just being able to add the spheres one by one in a very slow fashion would be OK, right now Blender is unresponsive.
This is due to the material.
As all your objects share the same data, adding the material will add many material slots to the same data. This is visible in the material property of the object: give it a try with n = few objects.
You'll see, for each of them (as same data) n material slots added:

So, remove the line:
object.data.materials.append(mat)

If you want this mat, add it previously to the ico mesh data or add it once after the loop:
mesh.materials.append(mat)

30k objects should be around 1mn (depending on your configuration).