9 comments

[ 6.4 ms ] story [ 40.4 ms ] thread
I appreciate that you first tried to optimize the original Python code. Idiomatic Python is unfortunately disappointingly slow and not so interesting to compare to.
I've generally taken the position that if you're considering doing micro optimizations in your python code you should just switch to another language instead. The gains from switching language are going to be so much higher than the gains from trying to get the python interpreter to be a little less slow (and empirically, every time I've seen it tried the code has been rewritten in the end anyway).
I wonder if these lints could have been expressed as semgrep rules?
It’s amazing how much Python punishes you for modularizing your code
I really enjoy making Python faster. I feel like the sweet spot for me is proving a concept with the dumbest possible implementation to show that something would work, and then using that as a comparison implementation to prove that later improvements match the results of the dumb, obviously correct implementation.
The second part, where it says that Rust is faster than Python, is so obvious than doesn't deserve any further comments. What I found interesting, is that idiomatic Python, with generators and all, can be so much worse than "C-style" Python, if you will pardon that term. It's a pity many kids are taught Python before C...