mesh.addFace() why is it so slow?

Hello,

I am loading a quite big mesh (~70000 verts and ~200000 faces).
The verts are loaded (appended) almost instantly but it really takes ages for the faces. I timed 32 seconds per 1000 faces, meaning ~1.5 hours to load the entire mesh!

I put the code below (taken from the Wiki official tut), any idea to speed it up very welcome!

Best,

Emmanuel

    for line in file.readlines():
	count +=1
	if count%1000 == 0:
		sys.stderr.write("line:"+str(count)+"

")

            words = line.split()
            if len(words) == 0 or words[0].startswith('#'):
                    pass
            elif words[0] == 'v':
                    x, y, z = float(words[1]), float(words[2]), float(words[3])
                    mesh.verts.append(Blender.NMesh.Vert(x, y, z))
            elif words[0] == 'f':
                    faceVertList = []
                    for faceIdx in words[1:]:
                            faceVert = mesh.verts[int(faceIdx)-1]
                            faceVertList.append(faceVert)
                    newFace = Blender.NMesh.Face(faceVertList)
                    mesh.addFace(newFace)

Here is another observation:

The speed at which face are added depends on the number of verts in the mesh.
Before I had about 70000 verts and adding 1000 faces took ~32s, now, with another mesh, I’ve got 20000 verts and then adding 1000 faces takes less than 20s.

Also, the more faces it adds, the slower it gets.

I guess I’ll have to check in the source code to understand what happens.

if your interested NMesh is older and not as well maintained.
Mesh works differently and may be better for what you want.
me.faces.extend([(v1,v2,v3), …])