The main reason I looked into this is I'm helping with the BlenderBIM add-on which can import IFC-files. The problem is many buildings can have several thousands of objects (my biggest IFC imported so far had 70k objects) and import is extremely slow because of the duplicate name check.
This patch probably needs some work if the general idea is accepted.
What it does is:
- Adds a GSet to Main to speed up checking if an ID name is free to use instead of looping through a ListBase. (improved from 9s to 5.8s to add 10,000 objects with random names)
- Switches to faster versions of atol and isdigit (7% speedup when separating a mesh to 10,000 new objects on Windows)
This script can be used to add 10,000 objects:
import bpy
import random, time
scene = bpy.context.scene
random.seed(12345)
N = 10000
S = 1 / pow(N, 0.333)
vertices = [ (0, 0, 0), (S, 0, 0), (S, S, 0), (0, S, 0) ]
faces = [ (0, 1, 2, 3) ]
l_random = random.random
last = t0 = time.time()
prev_tdiff = 1
for i in range(N):
x = l_random()
y = l_random()
z = l_random()
msh = bpy.data.meshes.new('mesh %d' % i)
msh.from_pydata(vertices, [], faces)
msh.update()
obj = bpy.data.objects.new('object %d' % i, msh)
obj.location = (x, y, z)
scene.collection.objects.link(obj)
now = time.time()
print('Create time: %.3fs' % (now - t0))