Making performance work easier in CPython

After chatting with folks at PyCon US, EuroPython and the sprint last week, I wanted to start a broader discussion about our benchmarking infrastructure and tooling. There are a few things I’d like to work on and would love input from folks.

Rehoming bench_runner into the Python org

I’d like to move bench_runner into the Python org on GitHub.

For those unfamiliar, bench_runner is what we use to run pyperformance through GitHub Actions on self-hosted runners. I’ve been using it for doesjitgobrrr.com for the better part of a year, and I know Meta and Arm have it configured as well.

This tool currently lives in the Faster CPython org, but I think it falls pretty squarely into Python org territory. I’d like to take on more of the maintenance and cleanup, including making the setup documentation easier to follow. I’ve documented my setup on my personal website to some degree, but it’d be good to bring that into the Devguide too.

I chatted with @mdroettboom about the move earlier this year, and he was supportive.

Our benchmark suite and workflow

This is a bigger and, I expect, more contentious topic, but there are a couple of things I’ve been thinking about:

  • Our benchmark mix: Small, focused benchmarks are useful, but I think we’d benefit from revisiting the balance of those and larger workloads. I’m also interested in how families of related benchmarks contribute to the overall geometric mean. For example, are we giving the various async-tree benchmarks the right collective weight? I also know anecdotally that there are benchmarks folks intentionally ignore because they don’t think they’re useful or good benchmarks. It’d be good to hear which ones and why.

  • Workloads: I think it would be valuable to have more recognizable macrobenchmarks: a modern web application, a data analysis workflow, an ML workload, etc. Having some agreed-upon workloads that we benchmark regularly across machines could help make performance improvements more tangible for people outside the project. It’s easier to connect a result to your own work when you recognize the application or workflow being measured. Richards, for example, probably doesn’t mean much to most end users.

  • Nightly runs: The nightly runs for doesjitgobrrr.com have been really useful for catching regressions and seeing whether optimizations help (see @kj0’s blog about this too). I think it could be valuable to build on this and make day-over-day performance tracking easier to follow for CPython more broadly (doespythongobrrr?). Maybe that eventually includes adapting the site into something that could replace speed.python.org.

A perf bot

There are a lot of times in PRs where we ask whether a change is worth it or what the performance delta actually is. Getting that answer can be slow and requires access to a benchmarking setup, or finding someone who has it.

I’d love something like a !perf command or a label on a PR that core team members could use to trigger benchmarks and get results compared to main. We’d probably need a subset of benchmarks or a more targeted run to make the turnaround useful during review. Details TBD, but something faster than two hours would be awesome.

So, a few questions to kick this off:

  • Are you supportive of some or all of these ideas?
  • For folks working on performance, what would help you get useful data faster?
  • Which workloads should we be paying more attention to?
24 Likes

Yes, let’s do it.

3 Likes

Benchmarking can be tricky to do. Two common issues are binary layout noise and noise on the benchmarking machine. For the layout noise I have no good suggestions, but for noisy systems (and almost all are) it would be great if the benchmarking tool (e.g. pyperf or something else) supports interleaving (at a fine level, e.g. 40 or more switches between two binaries). This gives more accurate results in less time.

Yes, I’d really like to see this. Microbenchmark can be quite sensitive. Sometimes a tiny change makes it look much better, but barely affects real-world workloads.

I think a web application benchmark would be a good choice, something like SPECjbb for Java. Python gets used a lot in AI, but I’m not sure ML workloads would tell us much about CPython’s own performance, since most of the bottlenecks might be on GPU or in PyTorch.

2 Likes

Very supportive overall.

I would really like one command to re-generate any metric CPython tracks over time. Currently I juggle a mix of pyperformance, pyperf microbenchmarks, and periodically memory.python.org runs and how to get to the benchmark code so I can run it with local system tools is always difficult. The complexity has made it harder for me to investigate when I spot a regression or proactively check things I think my change will effect.

There are additional metrics such as code size (gh-157407), individual test case run time, etc. which would be nice to gather metrics on over time.

To be clear here: The tool doesn’t need to support every setup, etc. Error if a tool, such as uv, or library is not installed but required. Opinionated set of core tools works for me.

1 Like

Thanks for putting together a plan, it’s a great start. Answering to your points:

I’d like to move bench_runner into the Python org on GitHub

Yes please, I know there are many forks/versions around, it would be great to have one that is well maintained.

I think it would be valuable to have more recognizable macrobenchmarks

I totally agree with it. Maybe we can start looking at GitHub - pyston/python-macrobenchmarks: A collection of macro benchmarks for the Python programming language · GitHub

IIRC, folks ran those as well when evaluating CPython performance

there are benchmarks folks intentionally ignore because they don’t think they’re useful or good benchmarks

yes, we should remove them. If we don’t want to remove them, we should group them together under the noisy group :slight_smile:
Internally we skip concurrent_imap, unpack_sequence.

Nightly runs

These can be done if we have a reliable infrastructure underneath. An yes, speed.python.org should be replaced with something more modern and useful

A perf bot

I support the idea to have automation to request performance on demand. Also it would be good to have the bot to run it with pystats, so it can collect stats about a specific change.

1 Like

And, if possible, on a range of CPU architectures and a mix of old and new CPUs. I’ve found that there can be dramatic performance differences when comparing ideas on ARM64 and x86_64, especially if there’s any use of relaxed atomics. Relaxed atomics are a lot faster on ARM64, so ideas that add some overhead but enable a speedup on x86_64 might end up being slowdowns on ARM64. And that was just comparing two different CPUs. I’m sure I would have seen dramatic differences if I started testing older and newer CPUs within the same architecture family.

3 Likes

Not sure if it’s relevant, but I was using a variant of this function to measure throughput for json libraries, because tuning the size manually was a pain:

from functools import partial
from timeit import timeit

def autosize(func, make_obj, target_time=0.2, maxsize=float("inf")):
    n = 1
    while True:
        timing = timeit(partial(func, make_obj(n)), number=1)
        if timing >= target_time or 2 * n > maxsize:
            return n, timing

        n *= 2

Instead of increasing the iteration count like autorange(), it increases the workload size.

Yeah, this is a good point. I know @thomas was looking into getting some official benchmarking machines set up again. I’m not sure yet what hardware we could get access to or what’s planned yet, but it’d be good to keep a mix of architectures and CPU generations in mind.

Maybe we could have a model similar to the buildbots, with folks contributing and maintaining dedicated benchmarking machines alongside any official hardware. We’d need to provide some setup and maintenance guidance, though, as those machines need to be quiet enough to get reliable results.

I already have my little home server farm that I’d be happy to keep contributing (everything listed here minus @diegor’s Sulaco machine).

Happy to repurpose that machine for benchmarks. At the moment it is a buildbot worker during the day and a benchmark machine for speed.python.org and the JIT brrr site during the night.

1 Like

Are you sure this is the right approach? In theory you should do benchmarks at different sizes.

I don’t know if bench_runner currently support this.

It think it depends on what you want to measure. I wanted to know which areas of the (en)coding pipeline could be improved, so I made fixed overhead neglible by using very large documents.[1]
But this obviously doesn’t tell you expected performance on real world data.


  1. Benchmark (Oct 20, 2026) - jsonyx 2.5 documentation ↩︎

1 Like

Maybe this is a long shot, but since we may revise the benchmarks selection, I would like to add that at this time we have a lack of parallel benchmarks. This makes it hard to spot where one change might have introduced scaling issues. (E.g. I spotted this one almost randomly while working on something else.)

AFAIU @colesbury had been using Zulip as a benchmark to find scaling bottlenecks, though I’m not exactly sure about his setup.

4 Likes

I’ve recently been working on revamping speed.python.org, and I’d love to improve it further to support this work, potentially integrating more machines as well.

If anyone has any ideas or suggestions, I’d love to hear them! So far, I’ve mostly been tidying up what was already there and adding a few new features, but my goal is to make it useful and accessible to all contributors. :slight_smile:

2 Likes

Dark Mode!
Not sure how but would be happy to submit a PR too :slight_smile:

1 Like

Quick update: the Steering Council approved the move of bench_runner to the Python org on GitHub yesterday. The repo now lives at GitHub - python/bench_runner: Code for running pyperformance benchmarks on Github Action runners · GitHub.

The old GitHub URL redirects to the new repo, so existing links and Git remotes should keep working.

4 Likes

Cool, the repository’s up at GitHub - python/codespeed: A fork of Codespeed that includes the instances run at https://speed.python.org/ and https://speed.pypy.org · GitHub, and we welcome contributions! However, in this case, I actually already have a patch for a dark mode (it’s just waiting on some codebase refactoring to land). It should be live dark hopefully in the next few days. :slight_smile:

1 Like

I’d really find this helpful, I opened Add option to run suite on PRs? · Issue #106 · python/codespeed · GitHub to discuss it (and implement once we settle on an idea).

I was thinking about this a bit differently. The goal is to make feedback available to the team as close to real time as possible, right in GitHub. A command or label on the PR would trigger bench_runner on dedicated benchmarking machines and post the results back.

Where we host the detailed results feels like a separate question. I’ve also been working on a dashboard for my runners, and I think there’s more to explore there, especially since repeated runs of unmerged PRs are a bit different from nightly tracking of main.

1 Like

@savannahostrowski

This is awesome!

One pattern we keep seeing is pasted pyperf (or timeit) snippets, eg:

@cmaloney touches on this in Making performance work easier in CPython - #5 by cmaloney .

This is also frequent from first-time contributors. These PR are small, isolated and generally good. The problem is that people forget about PGO+LTO builds and, generally, running benchmarks is hard, very hard on macOS, so the numbers get debated (examples: 1, 2, 3) and we we cannot always trust these numbers without spending our finite time on rerunning.

And pyperformance doesn’t really cover everything…

One idea would be introducing a section like <pyperf_snippet> in the PR description or in comments, or similar, that’d be also triggered with !perf.

There are some security implications but I believe they could be mitigated with labels (core team, triagers…). Not to mention that we’re already running the code from the PR itself, so this risk already exists (!).

+1 on self-hosted GH runners. They are crucial here, so we have the full control over general reproducibility (no variation over Azure/Github cloud), CPU isolation, pinning, the load on the machine and such. (It doesn’t require bare metal, though.)

2 Likes