bpy.data.meshes.new gets slower and slower I'm writing an importer add-on. It works, but it's slow. The first sub-file takes 15 seconds to import; out of it, 10 seconds are spent in bpy.data.meshes.new().

I timed it, and of course, it's fast at first, and it keeps getting slower.

While I can understand that (the scene is growing larger), is there anything I can do about it ? Like accessing the RNA directly or whatever, like this answer suggested ?

Here's the timings for my first sub-file : the first call to bpy.data.meshes.new() take 1ms, the 3000th takes 7ms.
Not a real answer, but more of a workaround : I manually merged the meshes by fiddling with the vertices arrays. So instead of creating 3000 meshes, I create only 1. Works in my use-case.

If it can help someone else, it looks like this:

lAllVertices = []
lAllTriangles = []

for fileToParse in allFilesToParse:
    lVertices, lTriangles = ParsePolygonalRep(fileToParse)

    # Before extending lAllTriangles, fiddle with the indices
    lCurrentIndexCount = len(lAllVertices)
    lTriangles = [(x+lCurrentIndexCount,y+lCurrentIndexCount,z+lCurrentIndexCount) for x,y,z in lTriangles]

    lAllVertices.extend(lVertices)
    lAllTriangles.extend(lTriangles)


lMesh = bpy.data.meshes.new(lMeshName)
lMesh.from_pydata(lAllVertices,[],lAllTriangles)
ob = bpy.data.objects.new("tmp", lMesh)
bpy.context.scene.objects.link(ob)