Skip to content

Tachyon hook#230

Merged
pablogsal merged 3 commits intopsf:mainfrom
maurycy:tachyon
Feb 10, 2026
Merged

Tachyon hook#230
pablogsal merged 3 commits intopsf:mainfrom
maurycy:tachyon

Conversation

@maurycy
Copy link
Contributor

@maurycy maurycy commented Jan 24, 2026

The PR adds support for profiling benchmarks with a Tachyon hook.

It's enabled only during benchmark execution. It supports nearly all flags as environment variables, and there's a guard for versions below 3.15. It's disabled on Windows, since I don't have access to any.

I'm not sure if this should be merged before October 2026, but it's a good way to verify Tachyon itself and offers a new way to profile the whole pyperformance suite.

Basic way to test:

uv run --python 3.15 -m pyperf timeit --hook tachyon '[x**2 for x in range(1000)]'

pyperformance

I was able to run the whole pyperformance suite with it:

PYPERF_TACHYON_OPTS="--flamegraph" \
PYTHONPATH=/home/maurycy/github.com/maurycy/pyperf \
uv run --python 3.15 --with /home/maurycy/github.com/maurycy/pyperf/pyperformance \
python -c "import pyperformance.cli; pyperformance.cli.main()" run \
  --fast \
  --hook tachyon \
  --inherit-environ PYPERF_TACHYON_OPTS

notes

  • Beyond the scope, but the hook subsystem could be more granular (any interest?), so WorkerTask etc. wouldn't be included,
  • profiling.sampling does not seem to offer a way to stop, except killing the process (not the urgent priority),
  • What would be the best way to write a test for it?

pyperf/_hooks.py Outdated
PYPERF_TACHYON_ALL_THREADS: Set to "1" to profile all threads
PYPERF_TACHYON_NATIVE: Set to "1" to include the native frames
PYPERF_TACHYON_ASYNC_AWARE: Set to "1" for async-aware profiling
PYPERF_TACHYON_EXTRA_OPTS: Extra arguments passed to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just calling it PYPERF_TACHYON_OPTS?

Copy link
Contributor Author

@maurycy maurycy Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vstinner Changed: 5791a4e

To be honest, I just copied the convention from perf_record:

@pablogsal
Copy link
Contributor

We can perhaps add a signal handler to the tachyon CLI invocation so you can request stopping. I think we react already to SIGINT so perhaps that works

@vstinner
Copy link
Member

vstinner commented Feb 6, 2026

I don't know hooks. How am I supposed to use them?

I tried the timeit command but it doesn't do anything special when using the tachyon hook.

$ PYPERF_TACHYON_EXTRA_OPTS="--flamegraph" python3.15 -m pyperf timeit "[1,2]*1000" --loops 2^17 -p3 --hook tachyon -q
Mean +- std dev: 1.43 us +- 0.01 us

Same issue when running a benchmark script:

$ PYPERF_TACHYON_EXTRA_OPTS="--flamegraph" python3.15 doc/examples/bench_func.py --hook tachyon -p3
....
sleep: Mean +- std dev: 1.07 ms +- 0.00 ms

@maurycy
Copy link
Contributor Author

maurycy commented Feb 6, 2026

I don't know hooks. How am I supposed to use them?

I didn't change Github description example to use PYPERF_TACHYON_OPTS after #230 (comment)

asciicast

Attaching the flame graphs:

The obvious problem is that it includes WorkerTask, because the hook subsystem is granular.

@maurycy maurycy requested a review from vstinner February 6, 2026 18:31
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

My example works with PYPERF_TACHYON_OPTS env var.

@pablogsal pablogsal merged commit 3f0cfc8 into psf:main Feb 10, 2026
12 checks passed
@pablogsal
Copy link
Contributor

Thanks for the PR @maurycy

@maurycy maurycy deleted the tachyon branch February 10, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants