Live data from Hacker News

You Should Compile Your Python and Here’s Why

glyph.twistedmatrix.com

1–10 of 109 posts

Re: You Should Compile Your Python and Here’s Why

#2
Some interesting tidbits on python code and compilation performance

1) During AoC I mostly used cpython and numpy. One day my code was running too slow so I fired up pypy. It ran even slower. Turns out numpy and pypy do not play well together in terms of performance.

2) I use matlab in work, and had some code that was slower than I liked, despite efforts to profile and optimise. I used the coder tool to compile it to C and got a 32x speedup. I was surprised, as matlab has a jit, so didn't expect a 32x performance delta, but there it is.

Re: You Should Compile Your Python and Here’s Why

#4
post #2

Some interesting tidbits on python code and compilation performance 1) During AoC I mostly used cpython and numpy. One day my code was running too slow so I fired up pypy. It ran even slower. Turns out numpy and pypy do not play well together in terms of performance. 2) I use matlab in work, and had some code that was slower than I liked, despite efforts to profile and optimise. I used the coder tool to compile it to…

What's AoC?

Re: You Should Compile Your Python and Here’s Why

#5
post #4
post #2

Some interesting tidbits on python code and compilation performance 1) During AoC I mostly used cpython and numpy. One day my code was running too slow so I fired up pypy. It ran even slower. Turns out numpy and pypy do not play well together in terms of performance. 2) I use matlab in work, and had some code that was slower than I liked, despite efforts to profile and optimise. I used the coder tool to compile it to…

What's AoC?

Advent of Code. Its a yearly coding challenge in December. Increasingly difficult problems each day, and an overall very fun way to brush up on algorithms or learn a new language.

Re: You Should Compile Your Python and Here’s Why

#7
post #6

This `mypyc` sounds too good to be true, I wonder what the catch's.

The obvious catch is that the compiled binary is not portable. You need to compile and deploy for each platform separately. You don't need to worry about platforms at all when deploying/sharing pure Python modules.

Re: You Should Compile Your Python and Here’s Why

#9
post #6

This `mypyc` sounds too good to be true, I wonder what the catch's.

"Mypyc is currently alpha software. It’s only recommended for production use cases with careful testing, and if you are willing to contribute fixes or to work around issues you will encounter."

At least for now, I wouldn't use it in production.

Re: You Should Compile Your Python and Here’s Why

#10
Thanks for writing this! I just reproduced your experiment and could get the ~10x performance gain (0.42/0.02) on my mac m1 (I had to uninstall typing - which hopefully gets fixed soon). I think this is a great way of attacking both type checking, as well as a meaningful speedup in the CI cycle.
Post reply on HN