How Fast is Python 3.15?
blog.miguelgrinberg.com
blog.miguelgrinberg.com
PyPy dates to 2007 (older than Pip!); back then I'm pretty sure people were still calling PyPI the Cheeseshop, and it was still hosted on the main python.org site for years after that (https://packaging.python.org/en/latest/guides/migrating-to-p...).
Not to mention that the PyPy name was established long before the initial release too. It was in development at least since 2003, under that name.
IIRC there was a PyPy talk at EuroPython 2003.
The first commit to the current repo is dated Feb 24, 2003, and the commit message is:
Move the pypy trunk into its own top level directory so the path names
stay constant.
...indicating there were previous history that got lost in the migration to hg or git.In the next episode of Complaining About Names; Why did those silly South Americans give their forest the same name as Bezos' company? :-)
We are moving every script we can to Go. Compared to bash it's a no-brainer, every dev can understand it, it has approximately .0000000000001% of the possible footguns, a great debugger, etc.
Almost all the rust compilation times come from needing to build the supporting libs. For simple scripts, it's very possible to get away with just using the std lib.
If you are at the point of doing multiple executions, you are probably at the point where converting your script to rust would end up saving time/power. Maybe not all the time (like a manually executed script), but not infrequently.
Also, of course, the majority of SaaS apps (perhaps most apps in general?) are not compute-bound, so gains from performance alone shouldn’t be the only metric.
My current job has a mix of Python and Go. Personally, I dislike Go. I don’t like its syntax, I don’t like its utter lack of formatting standards (gofmt is not a standard; also it sets tabs - ugh), I don’t like its insistence on static linking, and I don’t like how people claim it’s a great scripting language when you can’t just run a file on its own (and its stdlib is weak sauce compared to Python).
If you write slow rust, it's very easy to read, and still plenty fast.
There's a bunch of type direction you can do to get around this (`ReadConnection` vs `ReadWriteConnection` and some other magic), far from an immediate win but it's not impossible.
People talk about mutability a lot but the vast majority of Python code I see in the wild is SSA and has _very_ little mutability to begin with.
Of course ownership still has its costs. Lots of "I guess I'm copying this dict because I don't know if the owner will modify it or not" issues.
I think people overestimate how much they'll get from `&mut` annotations on business logic, and undersestimate how much line noise they'd get from a lot of the other stuff that happens in a lot of business logic.
Granted, I'm coming from a web-dev/Django perspective, where duck typing and overriding methods in subclasses is used heavily. And a lot of that doesn't have a nice 1:1 equivalent in the Rust model.
(I enjoy Rust BTW, just don't feel particular excitement about shuffling around strings in it)
Over the years, I've tried pypy and whatnot, but I've only ever seen between -30% and 30% speedups, depending on the code.
def fibonacci(k):
a,b=(0,1)
for i in range(k.bit_length()-1,-1,-1):
d=a**2
c=2*a*b-d
d+=b**2
(a,b)=(d,c+d) if k>>i&1 else (c,d)
return a
see https://oeis.org/wiki/User:Natalia_L._Skirrow/linear_recurre... (warning: old and bad and in need of revision), https://github.com/sympy/sympy/pull/30452 and https://github.com/sympy/sympy/pull/30541 for details of how to make similarly fast programs for arbitrary linear-recurrent sequences.you can also encode polynomials into integers; see https://mathstodon.xyz/@peterluschny/116320199782572958 and the following prog from https://codegolf.stackexchange.com/a/279771
lambda n:pow(p:=2<<n,n,p*p+~p)//p
both of these would be more intensive on the arithmetic side rather than control flowalso you could at least wrap the existing one in a `functools.cache`
I mention in the article that the reason I like the Fibonacci script that I'm using is that it is extremely slow, because recursion in Python is very slow. The point is to track improvements for the class of algorithms that rely on recursion.
Yes, some of the syntax is nice. But the rest of it, the scoping rules, the obstinacy around the lambda syntax, the venv/pip nonsense, path resolution etc is a hot mess. Were it not for astral tooling like uv, I would have abandoned it in a few weeks.
I hate thinking about memory outside of very specific workflows, so I am willing to accept a 2-3x penalty over C for cleaner and shorter code that follows the happy path. But anything beyond that and you are wasting energy and people's time.
For Python to work as something other than a glue language where we write all critical code in C/Rust and call it from inside Python, something like PyPy is almost mandatory. But the design of the language, the exposed innards, and the need to maintain backward compatibility makes optimization a chore.
I did some benchmarking of Python against C, Go, Rust, Node, LuaJIT etc in preparation for my runtime.[1] My observations based on some stats:
- You can blindly replace C with Rust for most tested workflows. There is very little performance difference outside of compiler speed. (C23 is a nice language though.)
- Go is 2-3x slower than C
- Node and LuaJIT are 3-8x slower on average compared to C
- Python is 60-70x slower. It can get far, far slower in certain cases.
You can run your own benchmarks. I think you might end up in the same ballpark.
[1] I have been interested in reverse engineering, hobbyist compiler/VM development etc for a couple of decades and wondered what is the point of ranting for two years about it without doing anything concrete. So I decided to build a runtime and statically typed language borrowing stuff from Python and Erlang/BEAM. But, even with LLMs implementing my ideas faithfully, the last 20-30% is a never-ending process which means I get bored and move on to something I can finish in 3-4 days.
Out of curiosity, have you seen if Cython[0] would provide any benefit to your runtime performance?
[0]: https://cython.readthedocs.io/en/latest/src/quickstart/cytho...
The situation is tricky and the friction is considerable. It is not like JS where v8 made the existing language blazing fast with no changes to the language itself.
Would rather use something like Nim with Python-like syntax.
Outside of that, though, what really grinds my gears about Python aside from its broad standard library compared to other languages is that it is home to what I think is the best property testing library in the world, Hypothesis. I know that the folks at Antithesis are working on getting Hegel [1] up and running, but they don't even have plans to support the language that my workplace prefers: C# (and I have been leading the charge in my workplace to keep up with the latest versions of .NET). Given how agents are now creating and modifying whole codebases, property tests live in that nice middle ground between unit tests and formal verification when it comes to validating (as best as we can) that the code works as intended.
I normally have one "tooling" language that I write all kinds of stuff in. And it goes beyond glue. So performance matters to me.
re: testing, I am pretty old-fashioned. I don't test everything. Only stuff that is critical or complex enough where I suspect breakage in the future. Also, I think borrowing ideas from Ada/Haskell/Clean etc for a new language could solve a lot of these pain points, now that LLMs are writing most of the code.
You're lucky to be able to control as much of the stack as you want with your one "tooling" language to rule them all so that performance matters again. Although in all fairness, given the regulatory and workplace culture as well as constrained budgets, sometimes you do have to let go of chasing performance in the name of making things easier for the maintainers at work. As I mentioned in a different post, it also helps to be working in a captive market, which helps relieve the pressure a bit.
Also, my Python ETL scripts do calculations for certain things, but attempting to speed that part up with a low level language like C or Rust doesn't really move the needle for total processing time when you have latencies measured in the hundreds of milliseconds per page of data. Scale that up to multiple pages and the whole runtime is dominated by how long it takes for packets to move from my Windows Server to Salesforce and back. It's basically a whole lot of effort for very little gain.
I get your usage. If you never spend enough time in slow mode, there is no point moving the code elsewhere as the savings do not justify the labor.
My issue is that I do not want to use or maintain code in 10 different languages. A single language, even one that is 3-5x slower than C would work. My only asks are that it should:
- be performant
- have basic infrastructure (cryptography, database etc)
- be aesthetically pleasing to read and write
It really doesn't for a lot of the things that matter, and people should seriously ignore your opinions if you're making these kind of fatuous jokes. Any serious person should understand what CPU bound tasks are vs what IO bound ones are. Python is used for the latter, with some C/C++/Rust bindings for the former. You are ignorant and tedious. When should I actually give a fuck? is the question that you types that build nothing never manage to answer. If you can improve some significant metric by 50x by moving away from Python, you should be fired for having been stupid enough to choose the wrong tool for the job.
This is a decision fork only when you are stuck using a slow language. I don't have to do this --- at all --- when using C/Java and so many other languages.
Using Python as glue and writing extensions in C/Rust is a choice. But I'd rather write everything in C23 by that point. Or move to a faster language if syntax/aesthetics is an issue.
Further, you often do not have a choice on what platform you get to work with. Someone might have built an expensive-to-replace website using PHP. And then you have to build HipHop to speed it up.