5 ms·
Just wondering, why is CPython a lot slower than JS? It seems to me that both languages are interpreted and comes with some reflection functionalities (like mod
by pca006132 5y ago
Just wondering, why is CPython a lot slower than JS? It seems to me that both languages are interpreted and comes with some reflection functionalities (like modifying object methods), but JS seems a lot faster in most of the benchmarks in https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
Edit: Why is this being downvoted? Is my statement incorrect or offensive to some people?
- pansa2 5y ago> It seems to me that both languages are interpreted Node.js uses the V8 engine for JavaScript which isn't just an interpreter - it includes a JIT compiler.
- dec0dedab0de 5y agoYes, the JIT has got to be the biggest difference. I wonder how node compares to pypy. I think when GVR mentions "There's machine code generation in our future" that he is talking about a JIT
- throwaway894345 5y agoI suspect Node is still quite a lot faster than Pypy because the former benefits from v8 which is a well-funded project which doesn’t have to worry about compatibility with the sprawling C-extension interface that CPython exposes.
- ForHackernews 5y agoI think mostly because Google has put a massive amount money and effort into making V8 faster. Performance has always been a lower-tier priority for cPython and other, faster, implementations (like PyPy) have not seen much mainstream adoption.
- epidemian 5y agoJS have been heavily optimized by browser vendors, fueled by the intense competition on the browser space, and the huge resources invested by companies like Google. IIRC Firefox 3 was the first browser to have what we would call a modern JS engine, with heavy emphasis on JIT compiling. Google Chrome soon followed and V8 dominated the JS perf story. Python doesn't have such fierce competition of implementations. And besides, it has the "escape hatch" of being able to implement performance-critical code paths as C extensions, which is what heavy-lifting libraries like numpy do.
- est 5y ago> Python doesn't have such fierce competition of implementations Python have many competitions, but the language lack some sort of spec and the only reference is CPython.
- el_oni 5y agoI think they were refering to a lack of interpreter competition. Sure there is pypy, jython, ironpython etc. But they arent competing. They are just used for different usecases. In the browser space their has been a lot of competition to make the fastest js runtime because it makes the browser faster.
- BiteCode_dev 5y agoMoney.
- scatters 5y agoCPython has a C API. Any Python object may at any time be passed into a C extension that expects to see all its introspectible attributes, nicely type-erased. This inhibits inlining, elision and monomorphization, all essential optimization techniques available to the JavaScript JIT.
- dragonwriter 5y ago> Just wondering, why is CPython a lot slower than JS? Because no FAANG has ever seen CPython performance as a central element of an effort central to the future of the firm, and thrown money at it accordingly.