22 ms·
With JavaScript, these kinds of optimizations in an engine make sense due to the web being limited by it and thus speed is a huge factor. With Python, however,
by uncomputation 4y ago
With JavaScript, these kinds of optimizations in an engine make sense due to the web being limited by it and thus speed is a huge factor. With Python, however, if a Python web framework is “too” slow, I would honestly say the problem is using Python at all for a web server. Python shines beautifully as a (somewhat) cross platform scripting language: file reading and writing, environment variables, simple implementations of basic utilities: sort, length, max, etc that would be cumbersome in C. The move of Python out of this and into practically everything is the issue and then we get led into rabbit holes such as this where since we are using Python, a dynamic scripting language, for things a second year computer science student should know are not “the right jobs for the tool.”
Instead of performance, I’d like to see more effort in portability, package management, and stability for Python because, essentially since it is often enterprise managed, juggling fifteen versions of Python where 3.8.x supports native collection typing annotations but we use 3.7.x, etc. is my biggest complaint. Also up there is pip and just the general mess of dependencies and lack of a lock file. Performance doesn’t even make the list.
This is not to discredit anyone’s work. There is a lot of excellent technical work and research done as discussed in the article. I just think honestly a lot of this effort is wasted on things low on the priority tree of Python.
- rmbyrro 4y agoTotally agree that performance is not on my top 10 wish list for Python. But I disagree on "not the right jobs for the tool". Python is extremely versatile and can be used as a valid tool for a lot of different jobs, as long as it fits the job requirements, performance included. It doesn't require a CS degree to know that fitting job requirements and other factors like the team expertise, speed, budget, etc, are more important than fitting a theoretical sense of "right jobs for the tool".
- blagie 4y ago> It doesn't require a CS degree to know that fitting job requirements and other factors like the team expertise, speed, budget, etc, are more important than fitting a theoretical sense of "right jobs for the tool". It requires experience. A lot of those lessons only come after you've seen how much more expensive it is to maintain a system than to develop one, and how much harder people issues are than technical issues. A CS degree, or even a junior developer, won't have that.
- rmbyrro 4y agoExperience does not lead to that conclusion. Whether Python will be easier or harder to maintain depends on numerous factors that vary so much for each job that you cannot generalize upon. That's something experience shows. Reaching such a conclusion that "Python is not a right tool for web backend" is just naive. No matter how experienced a developer is, reality of the world is at least 100x more diverse than what they alone could possibly have learned and experienced. If one believes to possess the experience of everything to generalize on complex topics like this, it just shows this person could benefit from cultivating a bit more humbleness.
- moffkalast 4y agoPython can do just about anything... but it will take its time doing it.
- rmbyrro 4y agoAnd many times this is negligible, which puts this out of the equation.
- blagie 4y agoI want a common language I can work with. Right now, Python is the only tool which fits the bill. A critical thing is Python does numerics very, very well. With machine learning data science, and analytics being what they are, there aren't many alternatives. R, Matlab, and Stata won't do web servers. That's not to mention wonderful integrations with OpenCV, torch, etc. Python is also competent at dev-ops, with tools like ansible, fabric, and similar. It does lots of niches well. For example, it talks to hardware. If you've got a quadcopter or some embedded thing, Python is often a go-to. All of these things need to integrate. A system with Ruby+R+Java will be much worse than one which just uses Python. From there, it's network effects. Python isn't the ideal server language, but it beats a language which _just_ does servers. As a footnote, Python does package management much better than alternatives. pip+virtualenv >> npm + (some subset of require.js / rollup.js / ES2015 modules / AMD / CommonJS / etc.) JavaScript has finally gone from a horrible, no-good, bad language to a somewhat competent one with ES2015, but it has at least another 5-10 years before it can start to compete with Python for numerics or hardware. It's a sane choice if you're front-end heavy, or mobile-heavy. If you're back-end heavy (e.g. an ML system) or hardware-heavy (e.g. something which talks to a dozen cameras), Python often is the only sane choice.
- DeathArrow 4y ago>. R, Matlab, and Stata won't do web servers. Not unless they're pushed to, like Python was. >A critical thing is Python does numerics very, very well. That's not Python doing numerical stuff. That's C code, called from Python.
- mrtranscendence 4y ago> That's not Python doing numerical stuff. That's C code, called from Python. That's sort of a distinction without a difference, isn't it? Python can be good for numeric code in many instances because someone has gone through the effort of implementing wrappers atop C and Fortran code. But I'd rather be using the Python wrappers than C or especially Fortran directly, so it makes at least a little sense to say that Python "does numerics [...] well". > Not unless they're pushed to, like Python was. R and Matlab, maybe. A web server in Stata would be a horrible beast to behold. I can't imagine what that would look like. Stata is a terrible general purpose language, excelling only at canned econometrics routines and plotting. I had to write nontrivial Stata code in grad school and it was a painful experience I'd just as soon forget.
- rootusrootus 4y ago> the problem is using Python at all for a web server I don't agree with this. Maybe for a web server where performance is really going to matter down to the microsecond, and I've got no other way to scale it. I write server code in both Javascript and Python, and despite all of my efforts I still find that I can spin up a simple site in something like django and then add features to it much more easily than I can with node. It just has less overhead, is simpler, lets me get directly to what I need without having to work too hard. It's not like express is hard per se, but python is such an easy language to work with and it stays out of my way as long as I'm not trying to do exotic things. And then it pays dividends later, as well, because it's really easy for a python developer to pick up code and maintain it, but for JS it's more dependent on how well the original programmer designed it.
- srcreigh 4y agoThe problem with Django services is the insanely low concurrency level compared to other server frameworks (including node). Django is single request at a time with no async. The standard fix is gunicorn worker processes, but then you require entire server memory * N memory instead of lightweight thread/request struct * N memory for N requests. I shudder to think that whenever Django server is doing an HTTP request to a different service or running a DB query, it's just doing nothing while other requests are waiting in the gunicorn queue. The difference is if you have an endpoint with 2s+ queries taking 2s for one customer, with Django, it might cause the entire service to stall for everybody, whereas with a decent async server framework other fast endpoints can make progress while the 2s ones are slow.
- pdhborges 4y agoYou can configure gunicorn to use multiple threads to recover quite a bit of concurrency in those scenarios and that is enough for many applications.
- srcreigh 4y agoWhat threading/workers configuration do you use? I'm looking at a page now which recommends 9 concurrent. requests for a Django server running on a 4 core computer. Meanwhile node servers can easily handle hundreds of concurrent requests.
- make3 4y agoI'm not sure it's very relevant to say in a discussion of the answer of "how do we improve Python" is "don't use Python". People have all kinds of valid reasons to use Python. Let's keep this on topic please
- robotsteve2 4y agoThe world doesn't revolve around web development. It's not the only use case. Scientific Python is huge and benefits tremendously from the language being faster. If Python can be 1% faster, that's a significant force multiplier for scientific research and engineering analysis/design (in both academia and industry).
- mrtranscendence 4y agoBecause most of the really huge scientific Python libraries are written as wrappers over lower-level language code, I'd be curious to what extent speeding up Python by, say, 10% would speed up "normal" scientific Python code on average. 1%? 5%?
- animatedb 4y agoIf you are talking about large sets of numbers, then the speed up will be far below 1%.
- pjmlp 4y agoAgreed, my only use for Python since version 1.6, is portable shell scripting or when sh scripts get too complicated. Anything beyond that, there are compiled languages with REPL available.
- mrtranscendence 4y agoWhat compiled languages do you have in mind? I suppose technically there are repls for C or Rust or Java, but I wouldn't consider them ideal for interactive programming. Functional programming might do a bit better -- Scala and GHCi work fine interactively. Does Go have a repl?
- pjmlp 4y agoJava, C#, F#, Lisp variants, and C++. Eclipse has Java scratchpads for ages, Groovy also works out for trying out ideas and nowadays we have jshell. F# has a REPL in ML linage, and nowadays C# also shares a REPL with it in Visual Studio. Lisp variants, going at it for 60 years. C++, there are hot reload environments, scripting variants, and even C and C++ debuggers can be quite interactive. I used GDB in 1996, alongside XEmacs, as poor man's REPL while creating a B+Tree library in C. Yes, there are Go interpreters available, https://github.com/traefik/yaegi https://github.com/traefik/yaegi
- cozzyd 4y agoParticle physicists have been using interpreted c++ for "macros" forever. First using the terrible hack of cint, now using cling which is quite good.
- pjmlp 4y agoIndeed, although I remember there used to be some commercial ones as well, from ads on The C/C++ Users' Journal and Dr. Dobbs.
- eatonphil 4y ago> compiled languages Might be tripping you up. Very few languages require that implementations be compiled or interpreted. For most languages, having a compiler or interpreter is an implementation decision. I can implement Python as an interpreter (CPython) or as a compiler (mypyc). I can implement Scheme as an interpreter (Chicken Scheme's csi) or as a compiler (Chicken Scheme's csc). The list goes on: Standard ML's Poly/ML implementation ships a compiler and an interpreter; OCaml ships a compiler and an interpreter. There are interpreted versions of Go like https://github.com/traefik/yaegi https://github.com/traefik/yaegi. And there are native-, AOT-compiled versions of Java like GraalVM's native-image. For most languages there need be no relationship at all between compiler vs interpreter, static vs dynamic, strict or no typing.
- Barrin92 4y ago>Python shines beautifully as a (somewhat) cross platform scripting language Python is much more than just a scripting language. I remember attending this talk[1] a few years about JPMorgan's 35 million LOC Python codebase. Python is being used to built seriously large software nowadays and I don't think performance is ever a minor issue. It should always be in the top 3 for any general purpose language because it directly translates into development speed, time and money. [1]https://youtu.be/ZYD9yyMh9Hk https://youtu.be/ZYD9yyMh9Hk
- dirnctiwnsidj 4y agoThis sounds like sour grapes. Python is a general-purpose language. Languages like Awk and Perl and Bash are clearly domain-specific, but Python is a pretty normal procedural language (with OO bolted on). The fact that it is dynamic and high-level does not mean it is unsuited for applications or the back-end. People use high-level dynamic languages for servers all the time, like Groovy or Ruby or, hell, even Node.js. What about Python makes it unsuitable for those purposes other than its performance?
- heavyset_go 4y ago> Also up there is pip and just the general mess of dependencies and lack of a lock file. You can use pyproject.toml or requirements.txt as lock files, Poetry can use the former and poetry.lock files, as well.
- waprin 4y agoOn paper, Python is not the right tool for the job. Both because of its bad performance characteristic and because it’s so forgiving/flexible/dynamic , it’s tough to maintain large Python codebases with many engineers. At Google there is some essay that Python should be avoided for large projects. But then there’s the reality that YouTube was written in Python. Instagram is a Django app. Pinterest serves 450M monthly users as a Python app. As far as I know Python was a key language for the backend of some other huge web scale products like Lyft, Uber, and Robinhood. There’s this interesting dissonance where all the second year CS students and their professors agree it’s the wrong tool for the job yet the most successful products in the world did it anyway. I guess you could interpret that to mean all these people building these products made a bad choice that succeeded despite using Python but I’d interpret it as another instance of Worse is Better. Just like Linus was told monolithic kernels were the wrong tool for the job but we’re all running Linux anyway. Sometimes all these “best practices” are just not how things work in reality. In reality Python is a mission critical language in many massively important projects and it’s performance characteristics matter a ton and efforts to improve them should be lauded rather than scrutinized.
- ChrisLomont 4y ago>the most successful products in the world did it anyway A few successful projects in the world did it. There's likely far more successful products that didn't use it. The key metric along this line is how often each language allows success to some level and how often they fail (especially when due to the choice of language). >should be lauded rather than scrutinized One can do both at the same time.
- digisign 4y agoThe folks that work on performance are not the folks working on packaging. Shall we stop their work until the packaging team gets in gear?
- marius_k 4y ago> and lack of a lock file Is it possible to solve your problem using pip freeze?
- the__alchemist 4y agoI agree! Here's a related point: Rust seems ideal for web servers, since it's fast, and is almost as ergonomic as Python for things you listed as cumbersome in C. So, why do I use Python for web servers instead of Rust? Because of the robust set of tools of tools Django provides. When evaluating a language, fundamentals like syntax and performance are one part. Given web server bottlenecks are I/O limited (mitigating Python's slowness for many web server uses), and that I'd have to reinvent several wheels in Rust, I use Python for current and future web projects. Another example, with a different take: MicroPython, on embedded. The only good reason I can think for this is to appeal to people who've learned Python, and don't want to learn another language.
- aldonius 4y agoSo really, you're not so much writing Python as writing Django, which just so happens to be Python.
- totony 4y ago>Instead of performance, I’d like to see more effort in portability, package management, and stability for Python because, essentially since it is often enterprise managed, juggling fifteen versions of Python where 3.8.x supports native collection typing annotations but we use 3.7.x, etc. is my biggest complaint. Also up there is pip and just the general mess of dependencies and lack of a lock file. Performance doesn’t even make the list. I have been leading a Python project lately and, yes, the tooling is very poor, although it is getting better. I have found poetry to be a very good for venv management and lock files + having one file for all your config.
- erosenbe0 4y agoPip has a decent solution for lock files: https://pip.pypa.io/en/stable/user_guide/#constraints-files https://pip.pypa.io/en/stable/user_guide/#constraints-files