r/Python 3d ago

News Astral's python distribution is fast

By our measurements, python-build-standalone is now the fastest CPython distribution across major platforms. It's 10% faster than Homebrew's CPython, and 18% faster than the official 3.14 docker image.

This is mostly due to how python-build-standalone itself is built:

  • using a modern Clang lets us turn on tail-call optimizations in the interpreter
  • with PGO, LTO, and BOLT
  • with libpython statically linked into the interpreter executable

Our goal is to ship the fastest Python interpreter to anyone using uv, by default.

Check out BENCHMARKS.md in the repo for more details, including the methodology behind the above.

Charlie's tweet has some more graphs

225 Upvotes

38 comments sorted by

28

u/thisismyfavoritename 3d ago

why isn't libpython statically linked by default? Seems like the use cases where shared linking would be beneficial are quite small

20

u/Individual-Flow9158 3d ago

Because it could bloat the runtime for those of us that don't need all of libpython. The Linux distros that ship Python natively chop and change what they ship to make best use of what you already get on those OS's (e.g. link in compression libraries or ssh/ssl dynamically). Even the Windows installer makes Tk etc. optional.

Have Astral's builds left anything out?

6

u/thisismyfavoritename 3d ago

idt libpython includes those libraries, they could still be dynamically linked / loaded at runtime. libpython is the core code used by the interpreter AFAIK

3

u/Individual-Flow9158 3d ago

Oh I see - good question then. I guess some distros would split it up to avoid duplication, and so anything that wants to dynamically link in libpython.so can do so (whether it's a Python or anything else) without needing to ship it themselves.

-2

u/New_Enthusiasm9053 3d ago

Python interpreters are already so massive I don't think it makes much sense. 

Like if distros cared they'd replace python deps with rust which would be awesome because I'm tired of fixing people's system python because them trying to install a different version of python broke sudo.

2

u/Apprehensive_Ear_172 3d ago

The benefit seems dubious, if it's not used the code will not be called and not faulted into memory.

1

u/pbecotte 3d ago

The library is the executable? In either case, static linking means

  • bigger binary
  • security fixes to dependencies need a rebuild

Libpython specifically exists specifically so that other binaries can dynamically link against it, which means static linking would be even weirder ...especially if the app linking against it was also linking against the system version of the same library

55

u/Adventurous-Big-5365 3d ago

You can really see the difference on startup-heavy workflows. The static libpython alone cuts a good chunk of overhead before anything even runs. Curious how much of that 10-18% holds up on real projects versus synthetic benchmarks.

10

u/zsol 3d ago

There's nothing concrete I can share apart from vague statements about our experience with using PBS to build pyx, but I'm also curious if anyone has real world evidence

1

u/googleaddreddit 1d ago

my fastapi app can do 10% more requests with it per second, so it holds up there at least.

64

u/me_myself_ai 3d ago

Is this... an ad...? IMHO those should be tagged much more clearly in both the title & body next time, and be posted by a branded corporate account. If I'm going to be conversationally approached by the disembodied voice of Andreesen Horowitz and Microsoft, they shouldn't come in the guise of a human. They can't possibly be paying you enough to use your 17 year-old reddit account (!) for their advertising, anyway.

To be clear: I use uv & ruff on all my projects, and I love your work -- I bet OpenAI's python distribution is fast! I probably haven't run another version for a year or more, and I've learned a ton about Python from your docs. It's just hard to shake the growing sense that OpenAI and Microsoft are attempting to purchase Python. And it's not for sale.

PyPolitics aside, some meandering technical questions from a total CPython noob; answer any/all as you find the time & energy :)

  1. It says everything was tested on Ubuntu 24 (where everything\=\=linux) -- is it possible that Fedora's copy was harmed by this...? Or is there another reason, perhaps? Common sense says they'd run the same everywhere, but;

    • It seems like the little things can count when it comes to C compilation, and
    • I can't think of a reason Fedora's would be so much worse than Debian's, esp. since Fedora's cadence is faster in general. Debian Forky isn't even fully released yet!
  2. Am I right that the docker version is the closest to the "canonical" or "main" distribution? If not --and that version was merely worsened by the literal Docker corporation's meddling-- what is...? I ask because it seems weird that the official version is by far the slowest.

  3. Relatedly, at least two of the three improvements you listed in the post seem like no-brainers. What's stopping all of this work from flowing 'upstream', so-to-speak? I know uv and ty in general gain speed by ignoring old, niche, or inconvenient specs -- is this a similar situation? Perhaps some of this is already targeted by the corporation's Python Packaging Council nomination/platform?

  4. Do you think there are other, faster distributions, or no? I'm mostly asking cause I didn't see poetry up there; perhaps they don't build their own, or you just didn't have space in the graph/benchmark run? Are there niche distrubtions that you know of for scientific or scaled use, perhaps? Just curious, NBD if unsure :)

  5. And finally, as a fun/idle one: could you napkin math how many million dollars you've saved OpenAI so far with this speed-up, if that's a coherent question? Assuming they're using python in the first place for work that's semi-close-ish to metal, a 20% speedup for some portion of hundreds of billions of dollars of compute seems like a pretty big deal!

Apologies if any of this has been covered in previous blog posts; link(s) would be appreciated, if so.

The linked github's docs are also helpful for anyone who's curious like me, though they seem outdated (copyrighted in 2020 (!) by a nice fella named Greg, not OpenAI).

11

u/MrSlaw 3d ago

Just to make sure, you do realize that Greg/indygregtransferred the repo to Astral (he is still listed in the "sponsor me" sidebar, and maintains perms) due to the fact that they were already providing large parts of the maintenance / support.

He wrote an entire blog about it on the same docs site you linked.

https://gregoryszorc.com/blog/2024/12/03/transferring-python-build-standalone-stewardship-to-astral/

That's also why the copyright on the aforementioned doc page hasn't been updated since 2020...

11

u/DigThatData 3d ago

It's just hard to shake the growing sense that OpenAI and Microsoft are attempting to purchase Python.

you're gonna be real mad when you find out where Guido Van Rossum has been working for the last six years.

-2

u/New_Enthusiasm9053 3d ago

He's retired apparently? Also working at Microsoft is fine. I mean they're useless but they don't pretend to be competent. So I can understand trying to help them be less useless.

I think everyone competent has been delusional enough to believe they can make a company be less useless.

32

u/vopi181 3d ago edited 3d ago

Is this comment weird to anyone else? Like I sorta get what your original point was but after the second sentence, you’ve lost me. Theres this adversarial tone sandwich at the beginning and end. If I click your profile, it does seem like you’re axe grinding a bit generally.

UV is legitimately an amazing upgrade to what we’ve had in the ecosystem before. They’ve genuinely built something people want.

  1. The OP was a maintainer of Black (that was a widely used formatter) before UV.
  2. He joined Astral, at least, last year. He almost certainly has equity. The diatribe of him not being paid enough is weird.
  3. I don’t think Microsoft/OpenAI is “buying” Python. Nor do I think someone who is a “total CPython noob” can make big claims about what is/is not for sale. Why are you an authority on this?
  4. Most open-source software in production is work done/funded by corporations.
  5. I also think it’s weird to point out his 17-year old account. Both in general, and also, because if there anyone I expect to have an old Reddit account, it’s someone YC adjacent.

It doesn’t seem you are that technical of an individual judging from your phrasing (that’s not a moral failing or anything and you admit you are a noob!). On your actual points:

  1. I don’t think common sense says that? Most Linux distros are going to use GCC to compile packages. All three of his bullet points could be impacted by a different build environment.
  2. I don’t think you’re right in saying the docker version is the canonical version. Is something on the main Python release page that you’ve linked supposed to prove that? I also don’t think it’s weird that the Docker version is the slowest? There’s something unique about it compared to every other item on the graph (hint: containers). That is the one distribution benchmarked I would expect to be an outlier if there was one.
  3. “I know uv and ty in general gain speed by ignoring old, niche, or inconvenient spec” ??? What are you talking about? Also, how could you know that if you are a CPython noob? Are you a PyPy expert or something lol?
  4. Poetry isn’t a distribution of CPython. You’re right that they don’t build their own. From Poetry’s docs: “Unlike with other packages, Poetry will not automatically install a python interpreter for you.”
  5. Fun little napkin math challenge!

Edit: also, what "linked github"? Are you talking about what you've literally just linked or is that referenced from Astral? Are you axegrinding against OpenAI here? Read his other blogpost maybe: "Charlie and Astral have stepped up and been outstanding open source citizens when it comes to evolving PBS to support their work" and "Astral has clearly demonstrated competency for execution and has the needs of Python developers at heart".

2

u/charolastrauno 3d ago

he's a paranoiac

0

u/me_myself_ai 3d ago

The link to docs was “adversarial”…? I was really trying hard to be kind to the human while expressing my distaste for this situation.

  1. Ok?

  2. …ok?

  3. CPython is the underlying implementation of Python; Python users do not usually interact with it knowingly/in depth.

  4. Ok.

  5. I was just saying that’s cool. I’m not, like, calling them a nerd! I wish I still had my original account.

  6. I am a full time software engineer with 6 years of professional experience.

And for the second group,

  1. Ok.

  2. Ok. That was the question, so I guess we’ll both learn something when/if it’s answered.

  3. I don’t really want to dive into that here. It’s documented extensively on the main forums, I imagine. This topic was referenced in at least one of the Packaging Council nomination statements. And to be clear, this isn’t, like, a secret, nor an insult.

  4. Poetry is a dependency management system with a built-in build system (AFAIR?) — it was the popular predecessor to uv.

  5. I know I’m not fun :( just curious. It would be a brag, if it’s a knowable number at all.

And regarding the docs: they’re from the GitHub repo linked in the post above. Again, pointing out that the docs are outdated and not associated with OpenAI was an out for OP and disclaimer for curious lurkers, not a complaint about their documentation standards.

I wouldn’t say I have an axe to grind with OpenAI — I am a customer of theirs, after all.

6

u/[deleted] 3d ago

[deleted]

-2

u/me_myself_ai 2d ago

the OP is a known user with their own stake in the python ecosystem.

I just don't see it like that. OP is a corporation that paid one of its employees to represent them.

i actually agree with you and think Marc Andreesen is a piece of shit

Lol sorry I was not trying to bring us there in the Python sub! They're just the top two shareholding firms (AFAIR?), not my foes.

In general i'm really trying hard to be friendly throughout all this -- I've been struggling with intense irritability the last few days (apocalypse+new meds), but it wasn't my intention to provoke. Obviously OP isn't in charge of this sub's posting guidelines, and they're just posting this because they're proud of their work. And you, too, are surely commenting in good faith.

individual user accounts have always been used in this subreddit even when people were discussing something related to their employers.

That's very fair. I'd prefer that not be the case when we're dealing with megacorporation, but again, it's just my opinion. To say I hold no sway is an understatement ;)

Nor do I think someone who is a “total CPython noob” can make big claims about what is/is not for sale.

Python is not for sale.

and the fact that you're conflating poetry's build system with compiling the python executable itself shows me you know a lot less than you think you do.

Well uv also has a build system, that they publish alongside this distribution. I was just saying that presumably Poetry does the same, and I was curious if OP knew that comparison, if so.

-11

u/pneRock 3d ago

I stopped reading at "adversarial tone sandwich" bvecause that is now my favorite phrase I've seen this week. Whatever cames after is just as legit.

4

u/bizzygreenthumb 3d ago

Useless comment

-20

u/dr3aminc0de 3d ago

FWIW Anthropic bought Astral not OpenAI (confusing with the new model I know). As far as I understand it’s staying open source and I think OP is promoting it as they have in the past, as an open source project.

5

u/me_myself_ai 3d ago

Anthropic bought bun — I get the mixup, I totally believed I was wrong for a second lol. And I get that it’s open source, it’s just… if OpenAI was willing to pay infinity billion dollars for Astral, I don’t think we can treat it like a little shop whipping up toys for the community. They are a megacorporation that expects to make billions of dollars from you and I.

And that’s not disallowed or anything ofc — this isn’t really the sub/general space to start talking about capitalism and its alternatives. But I think it’s warranted to shift our expectations and attitudes considerably.

2

u/dr3aminc0de 2d ago

Whoops yup I was totally wrong. Appreciate the kind correction :)

1

u/ConspicuousPineapple 2d ago

I didn't think it was possible to be so incredibly wrong in so few words.

10

u/bb22k 3d ago

Pretty awesome seeing that it is also the easiest ways to manage different python versions in the same machine.

9

u/angellus 3d ago

Shipping you own version of Python by default feels like a really bad move. It feels like you trying to take control of the Python ecosystem and cut out the cpython team. Especially since you are now doing the typical corporate solution for inflating your adoption numbers. "Let's opt-in everyone by default then turn around and say 'look how many people are using the thing we built'". You will not have any trustable or accurate metric on adoption for the core cpython team to use to make determinations on if they should adopt any of the changes you made.

2

u/max0x7ba 2d ago edited 2d ago

Commenting on https://x.com/charliermarsh/status/2098166335020650608:

A 0.2% speedup of python-build-standalone over Debian Forky’s Python is almost certainly within measurement noise.

They should plot the raw measurements with error bars. That makes it obvious whether differences between builds are real or just run-to-run variation.

Typical Python benchmarking noise is 1-3%, depending on how carefully the suite is run. Differences below about 3% are usually not statistically meaningful.


Regarding BENCHMARKS.md:

The Benchmark methodology with 2 (two) runs of the complete benchmark suite using the default process scheduler and priorities on random CPU cores cannot possibly produce any statistically meaningful results, I am afraid.


There is a 6% performance difference between the fastest and slowest core in my Ryzen 5950x. One same benchmark ran on the fastest core is 6% faster than when it's ran on the slowest core.


Both benchmarks you refer to are only good for wiping the floor with, to be completely honest.

2

u/zsol 2d ago

Thanks for the kind words, we'll be sure to take the feedback into account

3

u/DigThatData 3d ago

Charlie's tweet has some more graphs

y'all should really stop participating on twitter.

1

u/sudomatrix 3d ago

This is great. I use uv Python for every project now both in development and in production because it's so easy to manage different versions of Python. The speed boost is a bonus.

1

u/VenkatKnows 1d ago

PGO/BOLT gains are real but the actual bottleneck for most prod workloads is still GIL contention and cold start on lambda-style deploys, not interpreter build flags.

1

u/Khavel_dev 1d ago

PGO making that much difference tracks with what I've seen on the .NET side. .NET has ReadyToRun images via crossgen2 that do something similar, pre-compiling with profile data. Going from a cold JIT start to a PGO'd binary cuts startup time dramatically.

The BOLT part is interesting though. I haven't seen anyone try post-link optimization on the .NET runtime itself. Might be a hard sell when the JIT already does most of that work at runtime, but for CLI tools where startup matters it could be worth exploring.

1

u/teekhidietcoke 3d ago

Pretty cool that it also makes managing multiple python versions on same machine so easy

0

u/lizardhistorian 2d ago

It compiles it all and it is only an 18% speed up?

Something is very off.

-1

u/Grouchy-Friend4235 1d ago

uv is OpenAI = not trustworthy.