| ▲ | gozzoo 17 hours ago | |||||||||||||||||||||||||||||||||||||
I have quetion - slightly off topic, but related. I was wandering why is pyhton interpreter so much slower than V8 javascript interpreter when both javascript and python are dynamic interpreted languages. | ||||||||||||||||||||||||||||||||||||||
| ▲ | everforward 16 hours ago | parent | next [-] | |||||||||||||||||||||||||||||||||||||
I know of a couple reasons offhand. JavaScript is JIT’ed where CPython is not. Pypy has JIT and is faster, but I think is incompatible with C extensions. I think Pythons threading model also adds complexity to optimizing where JavaScripts single thread is easier to optimize. I would also say there’s generally less impetus to optimize CPython. At least until WASM, JavaScript was sort of stuck with the performance the interpreter had. Python had more off-ramps. You could use pypy for more pure Python stuff, or offload computationally heavy stuff to a C extension. I think there are some language differences that make JavaScript easier to optimize, but I’m not super qualified to speak on that. | ||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||
| ▲ | dragonwriter 15 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||
> why is pyhton interpreter so much slower than V8 javascript interpreter when both javascript and python are dynamic interpreted languages. Because JS’s centrality to the web and V8’s speed’s centrality to Google’s push to avoid other platform owners controlling the web via platform-default browsers meant virtually unlimited resources were spent in optimizing V8 at a time when the JS language itself was basically static; Python has never had the same level of investment and has always spent some of its smaller resources on advancing the language rather than optimizing the implementation. Also, because the JS legacy that needed to be supported through that is pure JS, whereas with CPython there is also a considerable ecosystem of code that deeply integrates with Python from the outside that must still be supported, and the interface used by that code limits the optimizations that can be applied. Faster Python interpreters exist that don’t support that external ecosystem, but they are less used because that ecosystem is a big part of Python’s value proposition. | ||||||||||||||||||||||||||||||||||||||
| ▲ | bheadmaster 17 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||
I can think of two possible reasons: First is the Google's manpower. Google somehow succeeds in writing fast software. Most Google products I use are fast in contrast to the rest of the ecosystem. It's possible that Google simply did a better job. The second is CPython legacy. There are faster implementations of Python that completely implement the API (PyPy comes to mind), but there's a huge ecosystem of C extensions written with CPython bindings, which make it virtually impossible to break compatibility. It is possible that this legacy prevents many possible optimizations. On the other hand, V8 only needs to keep compatibility on code-level, which allows them to practically switch out the whole inside in incremental search for a faster version. I might be wrong, so take what I said with a grain of salt. | ||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||
| ▲ | _ZeD_ 16 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||
keep in mind that, apart from the money throw at js runtime interpreters by google and others, there is also the fact that python - as a language - is way more "dynamic" than javascript. Even "simple" stuff like field access in python may refer to multiple dynamically-mapped method resolution. Also, the ffi-bindings of python, while offering a way to extend it with libraries written in c/c++/fortran/... , limit how freely the internals can be changed (see the bug-by-bug compatibility work done for example by pypy, just to name an example, with some constraint that limit some optimizations) | ||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||
| ▲ | int_19h 11 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||
Python is much, much more dynamic. E.g. look at how something as basic as accessing an attribute on an object works: https://docs.python.org/3/howto/descriptor.html Also Python has a de facto stable(ish) C ABI for extensions that is 1) heavily used by popular libraries, and 2) makes life more difficult for the JIT because the native code has all the same expressive power wrt Python objects, but JIT can't do code analysis to ensure that it doesn't use it. | ||||||||||||||||||||||||||||||||||||||
| ▲ | IshKebab 13 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||
Even though Javascript is quite dynamic, Python is much worse. Basically everything involves a runtime look-up. It's pretty much the language you'd design if you were trying to make it as slow as possible. | ||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||
| ▲ | screenothethird 16 hours ago | parent | prev [-] | |||||||||||||||||||||||||||||||||||||
[dead] | ||||||||||||||||||||||||||||||||||||||