Object creation slows over time I know that this has been asked before, but the answers that others have received did not help me much.  When creating objects through Python, using bpy.ops.mesh.primitive_cube_add() there is an exponential slowdown when looping the creation of objects.  My script that I am writing takes an image and creates a grid of cubes based on every pixel.  It also assigns a material to each cube based on each pixel's color.  When running it on a 32x32 image, it is very fast (about 1 second).  When running it on a 100x100 image, the script gets slower and slower as it runs.  I also have learned that using a low-level method to create my cubes I won't experience the slowdown.  I changed my code to a low-level method, and the speeds are much faster, but I still experience the slowdown.  

copy = ob.copy()
copy.data = ob.data.copy()
copy.data.materials.append(material)
copy.location.x = x - 1
copy.location.y = y - 1
copy.location.z = 1
bpy.context.scene.objects.link(copy)


Here is my current code for creating cubes.  My full addon can be accessed here: https://gist.github.com/MrSprite/ff7fda1ec4bf6850d357

Is there a faster/better way of doing this?  Because I would really like to be able to create 100,000+ cubes without waiting hours.

Thanks.
Some quick tests show that blender is designed to work with objects that have high vertex counts but not really with a large number of objects. Even with 3000 objects in a scene it takes a few seconds to select all objects, yet selecting the 33,000 vertices of those objects all joined together is almost instant.

I tested four ways to create multiple cubes.


Create 1000 cube objects - 8 seconds
Create a single mesh containing 1000 disconnected cube meshes - 0.5 seconds
As 2 then separate by loose parts to get 1000 cube objects - 5 seconds
Create a cube and a grid with 1000 verts, enable dupliverts and make real - 0.6 seconds


I am thinking your best approach would be to create a mesh that is a single plane with a vertex where you want each cube to be located, enable dupliverts, then if you want them separate for rigid body you can make the dupliverts real.

For info the script used to test these times is here.