3 ms·
I prefer functional style whenever I can. I noticed that this style slows Python programs down. It seems function calls are rather expensive. Does anybody have
by lysium 6y ago
I prefer functional style whenever I can. I noticed that this style slows Python programs down. It seems function calls are rather expensive. Does anybody have a similar experience?
- thisiszilff 6y agoYes, I suspect it is a pitfall of a multi-paradigm language that cannot assume so much about code in order to optimize. Opinionated functional languages (ie clojure, haskell) can have a lot more guarantees about what is going on in order to optimize all those function calls, lexical bindings, etc.
- vmchale 6y agoThere's a bunch of oddities in Python, e.g. recursion limits.
- AlexCoventry 6y agoIt's been a while since I knew those kinds of details, but it certainly been the case in the past. https://stackoverflow.com/questions/22893139/why-is-a-function-method-call-in-python-expensive https://stackoverflow.com/questions/22893139/why-is-a-functi...
- heavyset_go 6y agoPEP 590[1] makes calling callables less expensive. It was finalized for Python 3.9. [1] https://www.python.org/dev/peps/pep-0590/ https://www.python.org/dev/peps/pep-0590/
- lysium 6y agoThat sounds promising, thanks!
- vmchale 6y agoThey have to check a recursion limit, for one.