Remove extra comments. Use 64 bit integer math when possible. Use PyList_Append rather than foo.append() Use PyUnicode_AsUTF8String rather than codecs.encode() Make sure to raise an exception if the target directory doesn't exist. Seems to have made a significant performance impact.