3 ms·
There isn't much inherent in the language design which dictates it must be very slow, though. It's mostly a result of the canonical implementation.
by actionfromafar 4y ago
There isn't much inherent in the language design which dictates it must be very slow, though. It's mostly a result of the canonical implementation.
- yegle 4y agoTo have different implementations we first need a "Python language specification" which doesn't exist. All other implementations have to be compatible with CPython to increase their chance of getting wider adoptions.
- pjmlp 4y agoIndeed see Smalltalk, SELF, Common Lisp.
- bakal 4y agoThen how come that there have been so many forks focused on speed yet none has managed to get good enough?
- anakaine 4y agoGood enough in what way, specifically? Python is exceptionally popular not because of speed, but because of its wide compatibility, extensive list of maintained libraries, good learning paths, and most likely because its fast enough for most things. Every iteration of Python for some time now has added a not insignificant speed boost. It's not as fast as C, and nor will it be given how it works, but it certainly is fast enough for a great many situations and tasks. All of the above doesn't make it the right tool for every job. Sometimes you need to hit a nail, and you don't have a hammer but you do have a lump of hardwood. And in that situation, you make an assessment if in the long term you need to hit more nails regularly so you invest in a hammer, or just occasionally and you're ok with the lump of wood. It's subjective. So is it good enough? Good enough for what?
- thehappypm 4y agoThe speed of the programming language, in many applications, is a lot less relevant than the overall architecture. For example if you’re running a Web server and you’re serving a request through some hyper optimized C program, that is “fast”. But using a CDN in front of a slow Python server is almost always going to be faster for end users. Point is, the application is often just one part of a system. Python might let you develop quickly and avoid footguns, and having one slow link in the system doesn’t mean the system as a whole is gonna suck
- jakobnissen 4y agoI disagree. Python is inherently slow: * It uses an interpreter, which is slower than compiled code * All objects carry a dict to contain arbitrary attributes - this creates huge overhead * Even when the dict is suppressed with __slots__, all containers (all classes, even!) are untyped, so extracting any field causes dynamic dispatch * Objects cannot be stored inline in containers * Integers are variable-sized, and thus slower. Of course, you might counter that one could simply make a version of Python which is compiled, where all classes have a well-defined typed layout, where some classes can be immutable for performance, containers are typed, integers are machine integers, etc. But then I'd argue you're talking about a completely different language (Julia fits this description perfectly)
- itsoktocry 4y agoAnd despite all of this, Python has generated billions (trillions?) of value, and continues to do so. Perhaps it's you who is focussed on the wrong things? Maybe some of these issues can be improved over time? Maybe none of those things actually matter in the real world, outside of niche use cases?
- jakobnissen 4y agoAre you arguing about whether Python is a good language or whether it's a slow language? The former is a matter of taste, the latter is objectively true. And there are good reasons to believe it will remain true. It's created billions of dollars in value, sure. So had JavaScript and PHP. Doesn't mean they're good languages. Mediocrity gets you far, if you're at the right place at the right time.
- lozenge 4y agoSounds like Cython. PyPy did also fix some of those issues - specifically, lists of small integers are optimised, with a deopt path for when they overflow.
- jakobnissen 4y agoAll my points above are about the language semantics of Python, not the implementation. Some of them may be optimized some of the time with a clever enough JIT - but only a few of these points. That's why PyPy is not as fast as C.
- marcyb5st 4y agoI disagree as well. I was working at YouTube during the rewrite from python to c++ and a lot of people at Google looked at the problem to avoid a full rewrite of a major product. We still ended up doing it regardless of the pain of using Swig to wrap C++ code. Not missing that at all.