6 ms·
Is there a reason why Python must be slower than Javascript? I.e. given economic and cultural incentives, couldn't there be something like V8, for python?
by jstimpfle 10y ago
Is there a reason why Python must be slower than Javascript? I.e. given economic and cultural incentives, couldn't there be something like V8, for python?
- chrisseaton 10y agoNo, I don't know of anything in Python that could not be made as efficient as Javascript, using techniques that we already know about (and given the time and money that you've already acknowledged are also barriers). I'm not considering Python's C extensions there. I don't know if you'd consider that part of the 'language' or 'ecosystem'. Pyston is trying to make Python fast, including the C extensions, which is not as easy.
- the_mitsuhiko 10y agoJavaScript has fewer problematic features than Python which makes it possible to write efficient implementations. Also it has a standard which Python does not.
- fovc 10y agoWhat are the problematic features in Python that are not in JS? I'm not as familiar with JS
- optimuspaul 10y agoWhat do you mean Python doesn't have a standard? There is a very mature standard and process for managing that standard.
- chrisseaton 10y agoThere isn't a document describing the semantics of Python is there? That's what people mean by a 'standard'. Something at least trying to be somewhat semi-formal. If you mean that the implementation of CPython is a standard, well then I suppose that's arguable, but it's really not what anyone means.
- ak217 10y agohttps://docs.python.org/3.5/reference/ https://docs.python.org/3.5/reference/ I'm not sure why Armin is so categorical, but perhaps one way to rephrase what he said is that ES6 has had more opportunity to flesh out the spec/edge cases than Python, due to Javascript's popularity and healthy competition between implementations.
- the_mitsuhiko 10y agoBecause I spent months of my life a few years ago trying to work on modernizing the Python interpreter and it made me a bitter person. There is so much bizarre behavior in the interpreter that people depend on which is entirely undocumented and non standardized. Very few people know what even such a simple thing as "a + b" does in the language.
- chrisseaton 10y agoThe question was about whether it is technically possible to create a Python as fast as JavaScript, ignoring the money needed. So the number of features doesn't matter, only whether or not they are all possible to implement efficiently, and the lack of a standard doesn't matter, as with infinite money you could test comprehensively.
- jstimpfle 10y agoNo need to disqualify the answer. The point of my question was of course to learn about aspects of Javascript-the-language that make it intrinsically easier to build a fast implementation for than building one for python. If there are just more difficult-to-implement features that is interesting as well (although it would be nice to know which ones).
- the_mitsuhiko 10y agoBecause the interpreter internals shine through really badly. Leaves little room for obvious improvements.
- bpicolo 10y agoThere are python implementations that are much faster, and compare well to v8 speed (most notably, pypy)
- weberc2 10y agoThere are faster Python implementations, namely Pypy. I think one of the reasons Pypy isn't more popular is because it's C interoperability story is weaker than the reference Python implementation (CPython--not to be confused with Cython), or at least it's not compatible with many important C-based Python libraries (e.g., Pandas).
- adrianratnapala 10y agoThe C-compatbility story works both ways. I usually roll my eyes when people talk about making dynamic lanuages fast -- what's the point? In those cases where speed matters - use static language. As a result there is little incentive to use something like PyPy (although PyPy does have other nice features in addition to raw speed). But on the web there is a point. Unless you can use HTML alone, you have to use JavaScript -- and you can't just plug in a module that you wrote in C.
- cmdrfred 10y agoCan't you? Maybe not today, but soon. https://webassembly.github.io/ https://webassembly.github.io/
- static_noise 10y agoIt's about managing your resources. You can simply buy the fastest processor for cheap money. You can buy systems with many cores or even build a cluster for considerable money. But you can not buy time. Developing python applications in many cases is much quicker than developing comparable applications in C++, C or Assembler. Therefore it makes a lot of sense for many companies to choose tools with quick development time to get the product running and care for performance later. Since there may be so much code be written in python, it cannot simply be converted into a faster language since most critical parts are already accelerated using the proper libraries provided by the language ecosystem. Porting a complex application to another language in many cases is a really hard problem and might even not be possible to be done in smaller steps. Therefore we need every bit of performance we can squeeze out of python. The whole world will gain from that. If we manage great strides like JavaScript it would be glorious!
- indolering 10y agoAccording to the Pyston developers, yes[1]. [1] http://blog.kevmod.com/2016/07/why-is-python-slow/ http://blog.kevmod.com/2016/07/why-is-python-slow/
- cdavid 10y agoI am not a compiler/JIT expert by any stretch, but I have never heard of a strong technical reason why python could not be as fast as JS on V8 or compiled code produced by LISP compilers. But there are strong factors against it: * the reference implementation is maintained by a team of contributors, very few people are paid full time to work on cpython. State of the art JIT is hard to come by when you can only afford working a few hours / week. * contrary to JS, python had a huge set of packages available for a very long time, making "minor" language breaks unworkable. * also contrary to JS, python had from the start a strong story to interoperate w/ the C ABI, which tightened a large subset of python libraries with the details of cpython implementation. Because of its "niche", JS never really had that problem. If you remove libraries w/ large C extensions, you remove a lot of what make python popular today (e.g. scientific usage is now the 2nd largest area of application of python after web development, before automation, testing, etc... which used to be where python shined).
- cesnja 10y agoIt's possible, but Python doesn't need to be fast because it's used as glue for other (faster) languages like C. On the other hand, Javascript became the golden standard in its own niche (client-side web), there are no alternatives. Making it as fast as possible makes sense.