Hacker News new | ask | show | jobs
by lqdc13 3292 days ago
Blender Python lib by default is not optimized much. It has nothing to do with Python as a language.

Use numpy for matrices. If you have to implement an algo with a hot inner loop, use cython or numba.

I've never seen 100x difference in Python-C++ rewrite if Python was optimized already.

Here is a good article about some of the options: https://rare-technologies.com/word2vec-in-python-part-two-op...

1 comments

The one time I saw 100x increase in performance in Python-to-C (which was done through Cython) was in code that worked with strings calculating a machine-learning related distance between two strings. The code was doing a lot of accessing particular positions in the strings, which in pure python resulted in slow retrieval of every character (lots of .__getitem__ calls), which were optimized to having 2 predefined empty arrays (in heap, not stack, and their corresponding counters of valid items) and then walking the strings and storing the "hot" values in them.

So it was a very specific case where we could get that 100x speedup at work.

Just noticed after a while: it was "in the stack, not heap" (about the arrays).