17 ms·
Python 3.13 Gets a JIT
- deleted 3y ago[deleted]
- nerdponx 3y agoIndeed, this is exactly the kind of workload where PyPy historically outperformed CPython by a long shot. I think there have been incremental optimizations in the bytecode interpreter for things like this in recent versions, but a JIT is going to be a real game-changer. It will be interesting to see what happens to the PyPy project after this, as well as the HPy C API effort.
- boywitharupee 3y agothe title seems like a misnomer. shouldn't this be "python 3.13 gets a new jit compiler" because python already has a jit.
- ric2b 3y agoI think they mean CPython, yes.
- john61 3y agoAs great as such improvements are. Isn't it concerning for the future of Python's freedom that the president of the PSF is a Microsoft employee and a lot of important core devs are nowadays MS employees? Doesn't this give MS a great lever in the future the steer Python wherever they want it to be?
- hospitalJail 3y agoThere will always be a reason to use a language other than Python, but I'm finding more and more, 'why not use python'? Sure when my website/app/software gets 10k concurrent users, I might regret it, but I havent regretted it yet.
- sigma5 3y agofor those who missed it, the PR description is a poem https://github.com/python/cpython/pull/113465 https://github.com/python/cpython/pull/113465
- tus666 3y ago> The initial benchmarks show something of a 2-9% performance improvement. You might be disappointed by this number, especially since this blog post has been talking about assembly and machine code and nothing is faster than that right? Well, remember that CPython is already written in C and that was already compiled to machine-code by the C compiler. WTF has this to do with JITing the code written in Python?
- milliams 3y agoBrandt gave a talk about this at the CPython Core Developer Sprint late last year https://www.youtube.com/watch?v=HxSHIpEQRjs https://www.youtube.com/watch?v=HxSHIpEQRjs
- deleted 3y ago[deleted]
- ageitgey 3y agoFor the lazy who just want to know if this makes Python faster yet, this is foundational work to enable later improvements: > The initial benchmarks show something of a 2-9% performance improvement. > I think that whilst the first version of this JIT isn’t going to seriously dent any benchmarks (yet), it opens the door to some huge optimizations and not just ones that benefit the toy benchmark programs in the standard benchmark suite.
- Topfi 3y agoHonestly, 2-9% already seems like a very signficant improvement, especially since as they mention "remember that CPython is already written in C". Whilst it's great to look at the potential for even greater gains by building upon this work, I feel we shouldn't undersell what's been accomplished.
- adastra22 3y agoWhat is being accomplished then?
- gray_-_wolf 3y ago2-9%
- bomewish 3y agoAlso recall that a 50% speed improvement in SQLite was caused by 50-100 different optimisations that each eeked out 0.5-1% speedups. On phone now don’t have the ref but it all adds up.
- boxed 3y agoMany small improvements is the way to go in most situations. It's not great clickbait, but we should remember that we got from a single cell at some time to humans through many small changes. The world would be a lot better if people just embraced the grind of many small improvements...
- 3y ago
- eviks 3y ago> The initial benchmarks show something of a 2-9% performance improvement. You might be disappointed by this number, especially since this blog post has been talking about assembly and machine code and nothing is faster than that right? Indeed, reading the blog post build much higher expectations
- G3rn0ti 3y agoJust running machine code itself does not make a program magically faster. It‘s all about the amount of work the machine code is doing. For example, if the JIT compiler realizes the program is adding two integers it could potentially replace the code with two MOVs and a single ADD. However, what about the error handling in the case of an overflow? Python switches to its internal BigInt representation in this case and cannot rely on architecture specific instructions alone once the result gets too large to fit into a register. Modern programming languages are all about trading performance for convenience and that is what makes them slow — not because they are running an interpreter and not compiling to machine code.
- deleted 3y ago[deleted]
- fer 3y agoThe bit everyone wants: > The initial benchmarks show something of a 2-9% performance improvement. Which is underwhelming (as mentioned in the article), especially if we look at PyPy[0]. But it's a step forward nonetheless. [0] https://speed.pypy.org/ https://speed.pypy.org/
- woadwarrior01 3y ago> At the moment, the JIT is only used if the function contains the JUMP_BACKWARD opcode which is used in the while statement but that will change in the future. It's a bit less underwhelming if you consider that only function objects with loops are being JITed. nb: for loops in Python also use the JUMP_BACKWARD op.
- lifthrasiir 3y agoPyPy was never able to get fast enough to replace CPython in spite of its lack of compatible C API. CPython is trying to move fast without breaking C API, and 2--9% improvement is in fact very encouraging for that and other reasons (see my other comment).
- deleted 3y ago[deleted]
- cryptos 3y agoI always wondered how Python can be one of the world's most popular languages without anyone (company) stepping up and make the runtime as fast as modern JavaScript runtimes.
- tomwphillips 3y agoBecause enough users find the performance sufficient.
- rfoo 3y agoBecause the reason why Python is one of the world's most popular language (a large set of scientific computing C extensions) is bound to every implementation details of the interpreter itself.
- fer 3y agoEasy and the number-crunching libs are optimized away in (generally) C.
- PartiallyTyped 3y agoand FORTRAN.
- est31 3y agoPython is already fast where it matters: often, it is just used to integrate existing C/C++ libraries like numpy or pytorch. It is more an integration language than one where you write your heavy algorithms in. For JS, during the time that it received its JITs, there was no cross platform native code equivalent like wasm yet. JS had to compete with plugins written in C/C++ however. There was also competition between browser vendors, which gave the period the name "browser wars". Nowadays at least, the speed improvements for the end user thanks to JIT aren't also that great, Apple provides a mode to turn off JIT entirely for security.
- ephimetheus 3y agoI think usually the term “browser wars” refers to the time when Netscape and Microsoft were struggling for dominance, which concluded in 2001. JavaScript JITs only emerged around 2008 with SpiderMonkey’s TraceMonkey, JavaScriptCore’s SquirrelFish Extreme, and V8’s original JIT.
- p4bl0 3y agoThis was a fantastic, very clear, write-up on the subject. Thanks for sharing! If the further optimizations that this change allows, as explained at the end of this post, are covered as well as this one, it promises to be a very interesting series of blog posts.
- jagaerglad 3y agoCan someone explain what a JIT compiler means in the case of an interpreted language?
- irjustin 3y ago[flagged]
- cturner 3y agoThe article will be a confusing read to someone who does not know what a JIT is. Look at the paper after the heading "What is a JIT?" The first paragraph moves towards an answer - "compilation design that implies that compilation happens on demand when the code is run the first time" But then it backtracks on this and says that it could mean many things, and gets wishy-washy, and says that python is already a JIT. The second paragraph says, "What people tend to mean when they say a JIT compiler, is a compiler that emits machine code." What point is the author trying to make here? An Ahead of Time compiler emits machine code. But then it goes on to say that an Ahead of Time compiler also emits machine code. So what is a JIT? The third paragraph starts talking about about mechanism, which is a distraction from the question it posed above - what is a JIT? The article talks around points instead of making points.
- helboi4 3y agoYeah as a junior without a CS degree I was reading this article thinking "this is very interesting" but found it very hard to really grasp the difference between Ahead of Time and JIT from their explanations. Just that it was different from the previous python interpreter method, which seems woefully inefficient. I do know that Java has a JIT and I've read about this, but I guess it became quickly clear that I didn't really understand it since I couldn't follow this article. I think I will need to read more about this elsewhere and come back to fully grasp the impact.
- pjc50 3y ago> very hard to really grasp the difference between Ahead of Time and JIT JIT = "just in time" = bytecode is converted to native code while the program is running, either at the startup of the program or just before a particular function is called. Sometimes even after the function is called (since the JIT process itself takes time, it may be optimal to only run it once a function has been called N times or taken M microseconds total run time) AOT = "ahead of time" = bytecode is converted to native code before the program starts. i.e. by the developer during their distribution or deployment process. AOT compilation knows nothing about the specific run time conditions.
- LewisVerstappen 3y agoGreat article, but small typo when the author says "copy-any-patch JIT"
- ericvsmith 3y agoThat’s not a typo, that’s the name of the technique.
- kragen 3y agoi think it's 'copy-and-patch'
- ericvsmith 3y agoD’oh! Of course you’re correct. I skipped over “any”, and focused on “patch”. Sorry about that.
- kragen 3y agono harm done :)
- cqqxo4zV46cp 3y agoUnfortunate to see a couple of comments here drive-by pulling out the “x% faster” stat whilst minimising the context. This is a big deal and it’s effectively a given that this’ll pave the way for further enhancements.
- kragen 3y agomaybe, maybe not. time will tell. ahead-of-time compilation is even better known for improving performance and yet perl's compile-to-c backend turned out to fail to do that
- pjmlp 3y agoAhead-of-time compilation is a bad solution for dynamic languages, so that is an expected outcome for Perl. The base line should be how heavily dynamic languages like my favourite set, Smalltalk, Common Lisp, Dylan, SELF, NewtonScript, ended up gaining from JIT, versus the original interpreters, while being in the genesis of many relevant papers for JIT research.
- kragen 3y agowhen i wrote ur-scheme one of the surprising things i learned from it was that ahead-of-time compilation worked amazingly well for scheme. scheme is ruthlessly monomorphic but i was still doing a type check on every primitive argument i didn't realize they ever jitted newtonscript
- pjmlp 3y agoNewtonScript 2.0 introduced a mechanism to manually JIT code, functions marked as native get compiled into machine code. Had the Newton not been canceled, probably there would be an evolution from that support. See "Compiling Functions for Speed" https://www.newted.org/download/manuals/NewtonToolkitUsersGuide.pdf https://www.newted.org/download/manuals/NewtonToolkitUsersGu...
- 3y ago
- wrd83 3y agoHonestly I don't understand the pessimistic view here. I think every release since Microsoft started funding python has increased high single digit best case performance. Rather than focussing on the raw number compare to python 3.5 or so. It's still getting significantly faster. If they keep doing this steady pace they are slowly saving the planet!
- epcoa 3y agoSorry, but reality bites https://en.wikipedia.org/wiki/Amdahl%27s_law https://en.wikipedia.org/wiki/Amdahl%27s_law
- deleted 3y ago[deleted]
- vanderZwan 3y agoIt's not that simple. Amdahl's Law is about expected speedup/decrease in latency. That actually isn't strongly correlated to "saving the planet" afaik (where I interpret that as reducing direct energy usage, as well as embodied energy usage by reducing the need to upgrade hardware). If anything, increasing speed and/or decreasing latency of the whole system often involves adding some form of parallelism, which brings extra overhead and requires extra hardware. Note that prefetching/speculative execution kind of counts here as well, since that is essentially doing potentially wasted work in parallel. In the past boosting the clock rate the CPU was also a thing until thermodynamics said no. OTOH, letting your CPU go to sleep faster should save energy, so repeated single-digit perf improvements via wasting less instructions does matter. But then again, that could lead to Jevons Paradox (the situation where increasing the efficiency encourages more wasteful than the increase in efficiency saves - Wirth's Law but generalized and older, basically). So I'd say there's too many interconnected dynamics at play to really simply state "optimization good" or "optimization useless". I'm erring on the side of "faster Python probably good". [0] https://en.wikipedia.org/wiki/Jevons_paradox https://en.wikipedia.org/wiki/Jevons_paradox
- deleted 3y ago[deleted]
- pjmlp 3y agoFinally! Regardless of the work being done in PyPy, Jython, GraalPy and IronPython, having a JIT in CPython seems to be the only way beyond "C/C++/Fortran libs are Python" mindset. Looking forward to its evolution, from 3.13 onwards.
- dlahoda 3y agorust libs recently. pydantic for example
- livesinhel 3y agoAlso Polars.
- ElectronCharge 3y agoThe only way to achieve C/C++/Fortran efficiency is a statically compiled, strongly typed language. Witness the effort put into Java JITC and the rest of the modern Java (and Graal) runtime. Still well short of the promised “C equivalence”. To me, Mojo looks like the best approach to fusing that with the Python ecosystem! (I have no doubt about it being open sourced at some point.)
- bee_rider 3y agoJIT and static typing are not mutually exclusive or necessarily opposed. For example, MKL added JIT for small matrix multiplications quite a while ago. https://www.intel.com/content/www/us/en/developer/articles/technical/onemkl-improved-small-matrix-performance-using-just-in-time-jit-code.html https://www.intel.com/content/www/us/en/developer/articles/t... I think people just reach for JIT more often in dynamic languages because they carry more information around and have more of a performance deficit that they want to mitigate. I dunno. I mostly program in Fortran but JIT seems way cool. Fundamentally I don’t see why a JITer couldn’t beat my code in a very dynamic language, it would just need to find a big loop that calls a kernel a bunch of times, where the exact computation in the kernel is determined at run-time, and then jit the kernel and the loop together.
- Iridescent_ 3y agoWasn't CPython supposed to remain very simple in its codebase, with the heavy optimization left for other implementations to tackle? I seem to remember hearing as much a few years back.
- deleted 3y ago[deleted]
- toyg 3y agoThat was the original idea, when Python started attracting interest from big corporations. It has however become clear that maintaining alternative implementations is very difficult and resource-intensive; and if you have to maintain compatibility with the wider ecosystem anyway (because that's what users want), you might as well work with upstream to find solutions that work for everyone.
- lifthrasiir 3y agoThe copy-and-patch approach was explicitly chosen in order to minimize additional impacts on non-JIT-specific code base.
- hangonhn 3y agoDoes Python even have a language specification? I've been told that CPython IS the specification. I don't know if this is still true. In the Java world there is a specification and a set of tests to test for conformation so it's easier to have alternative implementations of the JVM. If what I said is correct, then I can see how the optimized alternative implementation idea is less likely to happen.
- oskarkk 3y agoWell, for Python the language reference in the docs[0] is the specification, and many things there are described as CPython implementation details. Like: "CPython implementation detail: For CPython, id(x) is the memory address where x is stored." And as another example, dicts remembering insertion order was CPython's implementation detail in 3.6, but from 3.7 it's part of the language. [0] https://docs.python.org/3/reference/index.html https://docs.python.org/3/reference/index.html
- vanderZwan 3y agoI think it's really cool that Haoran Xu and Fredrik Kjolstad's copy-and-patch technique[0] is catching on, I remember discovering it through Xu's blog posts about his LuaJIT remake project[1][2], where he intends to apply these techniques to Lua (and I probably found those through a post here). I was just blown away by how they "recycled" all these battle-tested techniques and technologies, and used it to synthesize something novel. I'm not a compiler writer but it felt really clever to me. I highly recommend the blog posts if you're into learning how languages are implemented, by the way. They're incredible deep dives, but he uses the details-element to keep the metaphorical descents into Mariana Trench optional so it doesn't get too overwhelming. I even had the privilege of congratulating him the 1000th star of the GH repo[3], where he reassured me and others that he's still working on it despite the long pause after the last blog post, and that this mainly has to do with behind-the-scenes rewrites that make no sense to publish in part. [0] https://arxiv.org/abs/2011.13127 https://arxiv.org/abs/2011.13127 [1] https://sillycross.github.io/2022/11/22/2022-11-22/ https://sillycross.github.io/2022/11/22/2022-11-22/ [2] https://sillycross.github.io/2023/05/12/2023-05-12/ https://sillycross.github.io/2023/05/12/2023-05-12/ [3] https://github.com/luajit-remake/luajit-remake/issues/11 https://github.com/luajit-remake/luajit-remake/issues/11
- checker659 3y agoM. Anton Ertl and David Gregg. 2004. Retargeting JIT Compilers by using C-Compiler Generated Executable Code. In Proceedings of the 13th International Conference on Parallel Architectures and Compilation Techniques (PACT '04). IEEE Computer Society, USA, 41–50. https://dl.acm.org/doi/10.5555/1025127.1025995 https://dl.acm.org/doi/10.5555/1025127.1025995
- vanderZwan 3y agoAnton Ertl! <3 Context: I've been on a concatenative language binge recently, and his work on Forth is awesome. In my defense he doesn't seem to list this paper among his publications[0]. Will give this paper a read, thanks for linking it! :) If they missed the boat on getting credit for their contributions then at least the approach finally starts to catch on I guess? (I wonder if he got the idea from his work on optimizing Forth somehow?) [0] https://informatics.tuwien.ac.at/people/anton-ertl https://informatics.tuwien.ac.at/people/anton-ertl
- mg 3y agoI love Python and use it for everything other than web development. One reason is performance. So if Python has a faster future ahead of it: Hurray! The other reason is that the Python ecosystem moved away from stateless requests like CGI or mod_php use and now is completely set on long running processes. Does this still mean you have to restart your local web application after any change you made to it? I heard that some developers automate that, so that everytime they save a file, the web application is restarted. That seems pretty expensive in terms of resource consumption. And complex as you would have to run some kind of watcher process which handles watching your files and restarting the application?
- onetoo 3y agoThe restart isn't expensive in absolute terms, on a human level it's practically instant. You would only do this during development, hopefully your local machine isn't the production environment. It's also very easy, often just adding a CLI flag to your local run command. edit: Regarding performance, Python today can easily handle at least 1k requests per second. The vast vast vast majority of web applications today don't need anywhere near that kind of performance.
- ubercore 3y agoBeen working with python for the web for over a decade. This is basically a solved issue, and the performance is a non-issue day to day.
- mg 3y agoThe thing is, I don't run my applications locally with a "local run command". I prefer to have a local system set up just like the production server, but in a container. Maybe using WSGI with MaxConnectionsPerChild=1 could be a solution? But that would start a new (for example) Django instance for every request. Not sure how fast Django starts. Another option might be to send a HUP signal to Apache: apachectl -k restart That will only kill the worker threats. And when there are none (because another file save triggered it already), this operation might be almost free in terms of resource usage. This also would require WSGI or similar. Not sure if that is the standard approach for Django+Apache.
- eterevsky 3y agoI'm even more excited to noGIL in 3.13. I wonder how these two features will play together?
- lucidguppy 3y agoIf python became fast, there's a chance it may become a language eater.
- teaearlgraycold 3y agoIMO the biggest issue with Python right now is the greater culture of code quality. This is probably biased from my recent exposure to ML code and ML packages. But there is a disgusting level of disregard for basic code practices in even fairly well funded libraries. Dead code, commented-out code, unused variables, unused imports, inconsistent quote types, unreadable variable names, no attempt to use type hints, etc. Granted, the code I see from more web and ops focused teams is miles better. But I worry the collective is not where it should be.
- csjh 3y ago2-9% isn't changing any language hierarchies
- poncho_romero 3y agoWhat languages do you think it could realistically eat (that it hasn’t already)?
- politelemon 3y agoJavascript, if it becomes viable for web development?
- fnord123 3y agoThis could be headed for another dead end imo. Context: I use python for data processing and webdev. When doing data processing, Python is merely glue for libraries in compiled languages. When doing webdev, I mostly use python itself. First, any numbers regarding benchmarks need to be treated with contempt. JITs are unbenchmarkable. No matter what you do, someone says you do it wrong. Warmed up the JIT? You did it wrong. Didn't warm up the JIT? You did it wrong. Warmed up and didn't warm up the JIT? Wrong. You lose predictable performance characteristics due to the above. It's difficult to describe the importance of this to the people who look at Python as glue for their compiled code. Next, on the face of it, it doesn't look like it will compose well with subinterpreters. If each subinterpreter does it's own tracing, it's going to be harder to hit the 10k watermark of jitting hot code. This uses LLVM's JIT which is particularly slow and heavy (16MB added to the binary size) last time I tried to use it. So this limits Python attractiveness in being an embedded language. While this remains experimental - and hence strictly optional, packaging this in distributions that use gcc would now apparently need llvm tools installed to build python. Expect feedback from distribution packagers. Idea for improvement: when I do data processing, I'm using python to glue bits of C, Rust, and other compiled languages so this is not very useful. When I'm doing webdev, it could be useful - and I am deploying using Docker. So why not make this AOT so I can add it to a docker build step and get all the benefit without the complications of tracing jits.
- robertlagrant 3y ago> So why not make this AOT so I can add it to a docker build step and get all the benefit without the complications of tracing jits. I've also thought this. If you're pre-baking your software, why not do this step as well?
- oblio 3y agoJS V8, Java (any JVM), .NET use JITs. If those aren't solid proving grounds for JITs, nothing is.
- guappa 3y agoAnd nobody writes short lived commands in those because of startup time.
- matsemann 3y agoWhat is it really JIT-ing? Given it says that it's only relevant for those building CPython. So it's not JIT-ing my Python code, right? And the interpreter is in C. So what is it JIT-ing? Or am I misunderstanding something? > A copy-and-patch JIT only requires the LLVM JIT tools be installed on the machine where CPython is compiled from source, and for most people that means the machines of the CI that builds and packages CPython
- lifthrasiir 3y agoCode fragments that implement each opcode in the core interpreter loop are additionally compiled in the way that each fragment is compiled into a relocatable binary. Once processed in that way, the runtime code generator can join required fragments by patching relocations, essentially doing the job of dynamic linkers. So it is compiling your Python code, but the compiled result is composed of pre-baked fragments with patches.
- kristianp 3y agoThank you and the gp for that insight.
- hawk01 3y agoIt never hurts for any language to get an uplift in performance. Exciting to see python getting that treatment
- nritchie 3y agoAt the end of the day, the number of optimizations that even a JIT can do on Python is limited because all variables are boxed (each time the variable is accessed the type of the variable needs to be checked because it could change) and then function dispatches must be chosen based on the type of the variable. Without some mechanism to strictly type variables, the number of optimizations will always be limited.
- vanderZwan 3y agoPer the spec all JS values are boxed too (aside from values in TypedArrays). The implementations managed to work their way around that too for the most part.
- johncolanduoni 3y agoCouldn’t you say the same for e.g. JavaScript? The variables aren’t typed there either and prototypes are mutable. I could definitely see things being harder with Python which has a lot of tricky metaprogramming available that other interpreted languages don’t but I don’t think it’s as simple as a lack of explicit types.
- btown 3y agoCan’t the happy path be branch predicted and speculatively executed, though? AFAIK V8 seems to do this: https://web.dev/articles/speed-v8#the_optimizing_compiler https://web.dev/articles/speed-v8#the_optimizing_compiler
- Joker_vD 3y agoIIRC Instagram's flavour of Python had unboxed primitives (if the types were constricted enough).
- make3 3y agojavascript is insanely more optimized but has the same limitations as Python. So there is likely a lot more you can do despite the flexibility, like figure out in hot code what flexibility features are not used, & optimize around that
- crabbone 3y ago
- jmdeschamps 3y agoMaybe the article should be dated "January 9, 2024" ??? (or is it really a year old article?)
- jmakov 3y agoHow's this different than running pypy?
- dagw 3y agoIt supports all your existing python code and python libraries (at the cost of being significantly slower than PyPy).
- jjice 3y agoThe last two-ish years have been insane for Python performance. Something clicked with the core team and they obviously made this a serious goal of theirs and the last few years have been incredible to see.
- pletnes 3y agoMicrosoft are paying core devs to work on it full time, for one.
- treyd 3y agoWhich is strange considering how bad the tooling to use Python on Windows is. There's a few workflows where people have gone down the beaten path before (Conda, etc.), but outside of that you have to just pretend you're on Linux and use the cygwin toolchains and even that doesn't always work so well. Better support on Linux was a top 5 reason for me making the switch to using it full time when I went off to college, and it hasn't changed substantially in the 8 years since then.
- BeetleB 3y agoNot sure what you mean. I use Python for Windows all the time at work, and on Linux at home. I've not noticed any meaningful difference in my workflow.
- deleted 3y ago[deleted]
- eigenvalue 3y agoIt’s because the total dollars of capitalized software deployed in the world using Python has absolutely exploded from AI stuff. Just like how the total dollars of business conducted on the web was a big driver of JS performance earlier.
- dehrmann 3y agoBut all the AI heavy lifting is done in native code.
- Pxtl 3y agoI still don't get why they didn't reduce API of the interpreter internals in Python 3 so that things like this would be more achievable. If you're going to break backwards compatibility, it's not like Unicode was the only foundational problem Python 2 had.
- peterfirefly 3y agoThey did change the API for Python modules implemented in C. That was actually part of the reason why the 2->3 transition went so badly. It wasn't realistic to switch to 3.x when the libraries either weren't there or were a lot slower (due to using pure Python instead of C code). It also wasn't realistic to rewrite the libraries when the users weren't there. It was in many respects a perfect case study in how not to do version upgrades.
- agounaris 3y agoa 2-9% improvement at global scale is insane! This is not a small number by any means.
- hyperman1 3y agoThe article presents a copy and patch jit as something new, but I remember DOS's quickbasic doing the same thing. It generated very bad assembly code in memory by patching together template assembly blocks with filled in values, with a lot of INT instructions toward the quickbasic runtime, but it did compile, not interprete.
- chc4 3y agoTemplate JITs in general aren't a new technique, but Copy-and-Patch is a specific method of implementing it (leveraging a build time step to generate the templates from C code + ELF relocations).
- PeterisP 3y agoTIL! I had used qbasic back in school, but I somehow always assumed that these basics were interpreters.
- rpeden 3y agoQBasic was a slightly cut down version of Quickbasic that didn't include the compiler, so your assumption was correct in that case. QBasic was bundled with DOS but you had to buy Quickbasic.
- hyperman1 3y agoI always assumed, because they where so similar, that they both were compilers, generating executable code in memory. qbasic just had the option to write a standalone .exe removed. I just saw the quickbasic compiler output, though, no idea if this guess is true. Now I wonder if a compiled executable was faster than an in-memory application.
- crabbone 3y ago[flagged]
- dang 3y agoCould you please stop posting flamewar comments, in particular about Python? You've done it repeatedly in this thread, as well as on many other occasions (e.g. https://news.ycombinator.com/item?id=38010109 https://news.ycombinator.com/item?id=38010109), and we've already had to ask you more than once to stop: https://news.ycombinator.com/item?id=38270168 https://news.ycombinator.com/item?id=38270168 (Nov 2023) https://news.ycombinator.com/item?id=37807607 https://news.ycombinator.com/item?id=37807607 (Oct 2023) This is not about Python, it's about not having tedious squabbles (or worse) on HN. We'd make the same request of any user on any topic. Sometimes a commenter is fixated on a particular topic, can't let go, and posts way too many low-quality and/or hostile comments about it. That's definitely not an ok use of HN, and we eventually have to ban such accounts. If you wouldn't mind reviewing https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html and taking the intended spirit of the site more to heart, we'd be grateful.
- crabbone 3y agoWell, as to the news guidelines... I'm sorry to say this, but they are either very easy to interpret many different ways, or are very frequently violated. I'm not complaining though. Any rule-based system to govern societies big or small will either be too rigid, or to prone to individual (mis-)interpretation. As for tedious squabbles, you seem to be the only one commenting on this post. You also don't seem to be interested in the subject. So, I don't see much potential for the squabble. ---- Anyhow. Since you welcomed a meta-response... here's another story. This time not a folk tale. Before Adobe bought Macromedia, Macromedia was in the process of revamping its tooling and workflows around Flash. They've created an open-source framework that included a compiler -- something that allowed for a much wider audience to start writing in ActionScript. They also significantly upgraded the language. The transition from AS2 to AS3 was in some ways more difficult than from Python 2.X to Python 3.X. Similar to how Python transition created a lot of zealotry, everyone in the world of Flash who wanted to post their opinion on the Web was cursing the old and praising the new. At the time I was a moderator on a user board dedicated to Flash and ActionScript. Just like everyone around me, I was hyped up about the advent of the new version of the language. Well, it wasn't every one though. There was one member of the forum who found himself in opposition to everyone around himself. He believed that the transition to AS3 was without merit, for show, a waste of time. Every time he'd appear in any forum thread, the discussion would inevitably shift towards AS2 vs AS3. At the time I thought he was ridiculously wrong... but the actual problem wasn't him being wrong. It was the quality of counter-arguments. Whenever someone disagreed with him, the counter-argument was laughably bad. So, let's call him "the AS2 guy", would spend time deconstructing the counter-argument showing how it's just a bad argument... but it was too much to read, and by the time there was a reply, there'd be a queue of more counter-arguments of similarly laughably low quality. Not surprisingly, the AS2 guy would get upset, threads would grow very long, eventually mods would start deleting posts and... temporary ban the AS2 guy. That is until we banned him permanently. I kind of felt bad for the guy, but thought it was for the greater good... As you can imagine, I believe I was wrong to ban him (well, the decision wasn't entirely mine, but that's going into too much detail). But this isn't the only thing I came to regret following the development of Web forums over last few decades. Below are some unfortunate revelations that I had at different times in connection to public discourse: * Opinions of more knowledgeable people are more polarized. * Most people in programming trade, if compared to other knowledge workers, have very little knowledge of their own trade. * Programmers have many naive beliefs about other areas of knowledge, believing ourselves to be experts in those fields for no good reason. This is particularly relevant when talking about programmers designing rules for online communities. As a result, programmers are very prone to creating self-reinforcing information bubbles. Designing and manipulating the rules of the system to secure a win of the opinion they subscribe to instead of refining their opinion to account for counter-arguments. The systems thus built are made to be less and less tolerant of a difference of opinion. Every superficially inclusive initiative, s.a. popular today "codes of conduct", becomes an instrument for fighting dissent. So, to tie back the story to the argument I'm trying to make: yes, of course I think Python is an awful technology. Yes, I never pretended that the people behind it are doing a good job. It's awful and it only gets worse. I also wrote plenty about the "why" side of things. I've never came across anything close to a convincing argument to the opposite, not here not in any other public forum that discusses Python. But there's often a lot of laughably bad arguments. If you choose to see my opinion as a violation of the forum rules -- that's up to you of course. But banning me for this will not make Python better, nor will it have any impact on my opinion, nor on my willingness to share it. It will, however, make some people feel better about themselves for a while. There's of course a possibility of remorse, but it doesn't come to everyone, and definitely not in a timely way.
- DeathArrow 3y agoIf JIT is a good thing for Python, why don't just compile to Java or .NET bytecode and use their already optimized infrastructure?
- crabbone 3y agoGiven how many Microsoft employees today steer the Python decision making process, I'm sure in not so distant future, we might see a new CLR-based Python implementation. Maybe Microsoft don't know yet how to sell this thing, or maybe they are just boiling the frog. Time will tell. But I'm pretty sure your question will be repeated as soon as people will get used to the idea of Python on JIT.
- _bohm 3y agoDoesn't this already exist in IronPython?
- Timothycquinn 3y agoCorrect. I just checked the project yesterday and they are presently at 3.4 :-|
- crabbone 3y agoIt's a lot about popularity / stigma. Microsoft developed both JScript and Node.js. They could've continued with JScript, but obviously decided against it because JScript didn't earn the reputation they might have hoped for. Even if they invested efforts into rectifying the flaws of JScript, it would've been just too hard to undo the reputation damage. Microsoft made multiple attempts to "befriend" Python. IronPython was one of the failures. They also tried to provide editing tools (eg. intellisense in MSVS), but kind of given up on that too (but succeeded to a large degree with VSCode). The whole long-term Microsoft's strategy is to capture and put the developers on a leash. They won't rest until there's a popular language they don't control.
- Gollapalli 3y ago“Python code runs 15% faster and and 20% cheaper on azure than aws, thanks to our optimized azurePython runtime. Use it for azure functions and ml training” Just a guess at the pitch.
- jokoon 3y agowhat are those future optimization he talks about? he talks about an IL, but what's that IL? does that mean that the future optimization will involve that IL?
- bbojan 3y ago> At the moment, the JIT is only used if the function contains the JUMP_BACKWARD opcode which is used in the while statement but that will change in the future. Isn't this the main reason why it's only a 2-9% improvement? Not much Python code uses the while statement in my experience.
- deleted 3y ago[deleted]
- darrenBaldwin03 3y agoWoah - very interesting!
- haberman 3y agoThe article describes that the new JIT is a "copy-and-patch JIT" (I've previously heard this called a "splat JIT"). This is a relatively simple JIT architecture where you have essentially pre-compiled blobs of machine code for each interpreter instruction that you patch immediate arguments into by copying over them. I once wrote an article about very simple JITs, and the first example in my article uses this style: https://blog.reverberate.org/2012/12/hello-jit-world-joy-of-simple-jits.html https://blog.reverberate.org/2012/12/hello-jit-world-joy-of-... I take some issue with this statement, made later in the article, about the pros/cons vs a "full" JIT: > The big downside with a “full” JIT is that the process of compiling once into IL and then again into machine code is slow. Not only is it slow, but it is memory intensive. I used to think this was true also, because my main exposure to JITs was the JVM, which is indeed memory-intensive and slow. But then in 2013, a miraculous thing happened. LuaJIT 2.0 was released, and it was incredibly fast to JIT compile. LuaJIT is undoubtedly a "full" JIT compiler. It uses SSA form and performs many optimizations (https://github.com/tarantool/tarantool/wiki/LuaJIT-Optimizations https://github.com/tarantool/tarantool/wiki/LuaJIT-Optimizat...). And yet feels no more heavyweight than an interpreter when you run it. It does not have any noticeable warm up time, unlike the JVM. Ever since then, I've rejected the idea that JIT compilers have to be slow and heavyweight.
- cbmuser 3y ago»LuaJIT is undoubtedly a "full" JIT compiler.« Yes, and it's practically unmaintained. Pull requests to add support for various architectures have remained largely unanswered, including RISC-V.
- dataangel 3y agoDoesn't change parent's point, clearly proves it's possible
- peterfirefly 3y agoI think Mike Pall has done enough work on LuaJIT for several lifetimes. If nobody else wants to merge pull requests and make sure everything still works then maybe LuaJIT isn't important enough to the world.
- kzrdude 3y agoHow do you access optimizations such as dead code removal and constant propagation using this technique?
- SpaghettiCthulu 3y agoI believe a JIT using this technique could eliminate dead code at the Python bytecode level, but not at the machine code level. That seems pretty reasonable to me.
- kzrdude 3y agoNot sure, these optimizations multiply in power when used together. Propagate constants and fold constants, after that you can remove things like "if 0 > 0", both the conditional check and the whole block below it, and so on.
- SpaghettiCthulu 3y agoThat's entirely possible with the approach I described. Such optimizations can easily be done on the bytecode prior to the compilation to machine code.
- divbzero 3y agoI love the description in the draft PR: 'Twas the night before Christmas, when all through the code Not a core dev was merging, not even Guido; The CI was spun on the PRs with care In hopes that green check-markings soon would be there; ... ... ... --enable-experimental-jit, then made it, And away the JIT flew as their "+1"s okay'ed it. But they heard it exclaim, as it traced out of sight, "Happy JIT-mas to all, and to all a good night!" https://github.com/python/cpython/pull/113465 https://github.com/python/cpython/pull/113465
- deleted 3y ago[deleted]
- thetinymite 3y agoThe PR message with a riff off the Night Before Christmas is gold. https://github.com/python/cpython/pull/113465 https://github.com/python/cpython/pull/113465
- deleted 3y ago[deleted]
- mixmastamyk 3y agoBetter than I expected, thanks.
- julienchastang 3y ago"by Anthony Shaw, January 9, 2023" 2024, right?
- deleted 3y ago[deleted]
- EmilStenstrom 3y agoIt's interesting to see these 2-9% improvements from version to version. They are always talked about with disappointment, as if they are too small, but they also keep coming, with each version being faster than the previous one. I prefer a steady 10% per version over breaking things because you are hoping for bigger numbers. Those percentages add up!
- bilsbie 3y agoSomeone please compare 3.13 to 2.3! I’d love to see how far we’ve come.
- frou_dh 3y agoI think it's more an issue of framing sometimes causing confusion, i.e. the ultimate trajectory is probably "crushingly slow → slow" rather than fastness coming in to it. (h/t https://news.ycombinator.com/item?id=35906158 https://news.ycombinator.com/item?id=35906158)
- technocratius 3y agoWell I think they even multiply, making it even better news!
- chmod775 3y agoI'd rather they add up. Minus -5% runtime there, another -5% there... Soon enough, python will be so fast my scripts terminate before I even run them, allowing me to send messages to my past self.
- meisel 3y agoWhy has it taken so much longer for CPython to get a JIT than, say, PyPy? I would imagine the latter has far less engineering effort and funding put into it.
- kstrauser 3y agoFor the longest time, CPython was deliberately optimized for simplicity. That's a perfectly reasonable choice: it's easier to reason about, easier for new maintainers to learn it, easier to alter, easier to fix when it breaks, etc. Also, CPUs are pretty good at running simple code very quickly. It's only fairly recently that there's been critical mass of people who thought that performance trumps simplicity, and even then, it's only to a point.
- nomel 3y ago> It's only fairly recently that there's been critical mass of people who thought that performance trumps simplicity This definitely wasn't true, from the user perspective. And, I'm not even convinced it's some "critical mass" of developers. These changes aren't coming from some mass of developers, there's coming from a few experts that had a clear plan, backed by the sanity of the huge disconnect that languages are actually meant for users of the language, not the developers of the language.
- arccy 3y agocritical mass of cpython devs
- MBCook 3y agoI believe PyPy was written knowing it wouldn’t work with many C/C++ libraries used in the Python world. That made it much easier to get bigger gains than if they wanted 100% backwards compatibility with CPython.
- ya3r 3y agoMaybe relevant blogpost is https://devblogs.microsoft.com/python/python-311-faster-cpython-team/ https://devblogs.microsoft.com/python/python-311-faster-cpyt... dated Oct 2022. The team behind this and some other recent improvements to Python are at Microsoft.
- t43562 3y agoI wish the money could be spent on PyPy but pypy has its problems - you don't get a big boost on small programs that run often because the warmup time isn't that fabulous. For larger programs like you sometimes it some incredibly complicated incompatibility problem. For me bitbake was one of those - could REALLY benefit from pypy but didn't work properly and I couldn't fix it. If this works more reliably or has a faster warmup then....well it could help to fill in some gaps.
- mattip 3y agoPyPy dev here. A little money could go along way to speeding up the PyPy base interpreter. Right now PyPy has no active income.
- t43562 3y agoThank you for the great work you've all done.
- MBCook 3y agoIsn’t that similar to JS? My understanding was modern JS runtimes had something like this: interpreted -> basic JIT -> fancy JIT The interpreter gets you going fast. The basic JIT is extremely fast to compile but not the most performant. If the code can be JITed it quickly will be. From there the engine can find hotspots or functions that get run a lot and use the fancy JIT on them in the background. That means the slow compile doesn’t block things but when the result can be swapped in performance can take a big jump. At any point the engine can drop down to the interpreter if an assumption is violated (someone passes a string where they had always used numbers before) or a function is redefined. It wouldn’t surprise me if something like that appeared as an option in Python over time to get the best of both worlds.
- igouy 3y agofigure 7 "Speculation in JavaScriptCore" 2020 Filip Pizlo https://webkit.org/blog/10308/speculation-in-javascriptcore/ https://webkit.org/blog/10308/speculation-in-javascriptcore/
- GGerome 3y agoWhat an horrible language..
- matheusmoreira 3y agoSo they compile the C implementation of every opcode into templates and then patch in the actual values from the functions being compiled. That's genius, massive inspiration for me. It's automatically ABI compatible with the rest of CPython too. Is there an similarly accessible article about the specializing adaptive interpreter? It's mentioned in this article but not much detail is given, only that the JIT builds upon it. I wonder if I can skip the bytecode compilation phase.
- deleted 3y ago[deleted]