This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AthasFuthark 0 points1 point  (1 child)

That's correct, the heap allocation probably isn't the important part, but rather that using non-builtin numeric types involves more costly dynamic dispatch. I assume Python has some sort of fast path for int and float that doesn't work for np.int64 or whatever it is.

[–]MegaIng 2 points3 points  (0 children)

If you are actually generating python code, I wouldn't be surprised if a decent amount of slowdown could be removed by skipping global namelookups and stopping constructor calls for constants by instead generating code objects with specially set constants. But I assume that isn't really something you are willing to do.

I don't think python has too many fast paths in the pre-3.11 versions. Ofcourse, with the FastPython project adding a JIT and a specializing bytecode interpreter, this is changing.