deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

Python 3.15's Tachyon Profiler Attaches to Running Processes Without a Restart

Python 3.15 ships a sampling profiler, code-named Tachyon, that attaches to live processes and reports per-line timings without a restart or code changes, replacing the usual cProfile or py-spy workflow.

Python 3.15's Tachyon Profiler Attaches to Running Processes Without a Restart

Profiling without a restart

Python 3.15, released on October 9, 2026 according to a walkthrough published on dev.to, ships a new standard-library module called profiling.sampling, known as Tachyon, that can latch onto an already-running process, sample its call stacks straight from memory and detach again — without restarting the process or touching its code.

That job previously fell to external tools such as py-spy, which must work out the memory layout of every new interpreter release and are often blocked from restricted production images, the author notes. Tachyon travels with the interpreter itself, and it also tackles the shortcomings that made cProfile a poor fit for production: per PEP 799, the proposal behind the package, cProfile watches only the main thread, adds overhead to every function call and can force some of the interpreter's own optimizations off.

Taking a snapshot of a live process

The walkthrough demonstrates the module on a small worker with a planted bug: it deduplicates a batch of orders by testing membership against a list instead of a set, making each lookup linear. With the process running in the background, python3.15 -m profiling.sampling dump $PID prints a single stack snapshot formatted like a traceback. The header matters as much as the frames: in the demo run it showed the thread holding the GIL and executing on a core, which immediately tells you the process is busy computing rather than blocked on I/O or a lock. Only the main thread appears by default; -a widens the dump to every thread, and --async-aware stitches stacks back together across await points in asyncio programs.

From one snapshot to a thousand per second

A lone snapshot may catch an unrepresentative code path, so the attach subcommand samples repeatedly — 1,000 times per second at the default rate — and counts where the samples land. A ten-second window over the demo worker gathered 10,000 samples: 55.1% inside fetch_batch, whose time.sleep stands in for a slow API call, and 44.0% inside the dedupe membership test. Attribution reaches individual line numbers, so the report says which expression inside a function is expensive, not just which function is.

Wall time and CPU time give different answers

Rerunning the same window with --mode=cpu, which keeps only samples captured while the thread was genuinely executing on a core, produced a very different table: dedupe took 97.9% of samples and JSON encoding just 0.7%. The author's rule of thumb is to match the mode to the complaint — wall time when users report slowness, CPU mode when the CPU graph is the alarm. Two further modes round out the set: --mode=gil counts only samples in which a thread holds the GIL, surfacing code that starves other threads in a threaded server, and --mode=exception counts samples taken while an exception is in flight, exposing libraries that lean on exceptions as control flow. On Unix-like systems, attach --live opens a continuously updated, top-style terminal view.

Proving a fix with a diff flame graph

Tachyon can record a compact binary baseline before a change, then sample the fixed process against it with --diff-flamegraph, emitting one self-contained HTML file. Frames that grew are shaded red, frames that shrank blue, and movements under 15% stay gray. After swapping the list for a set, the diff showed dedupe down 99%, and throughput climbed from 22 batches per ten seconds to 39.

The diff also contained a trap: the untouched sleep and the JSON encoder both came out red, flagged at roughly 75% worse, even though neither had slowed. Over a fixed ten-second window, a faster loop simply reaches unchanged code more often, so those frames inherit the sample share the fixed function gave back. In a wall-clock diff, red signals a larger slice of the window rather than costlier calls, so the author advises reading the colors alongside a throughput figure. A fresh wall profile of the repaired worker placed 98.1% of samples on the sleep — the honest next bottleneck, and a question about batching, concurrency or caching rather than more profiling.

The walkthrough closes with the preconditions for production use — permissions on Linux foremost among them — that decide whether attach works at all and how to interpret its output.

Why it matters

For on-call engineers, the core value is that diagnosis no longer requires destroying the evidence: restarting a wedged worker under cProfile discards both queued work and the conditions under investigation, while Tachyon observes them in place. Shipping with the interpreter removes the dependency on external profilers and the per-release compatibility work they demand, and per-line attribution plus a clean wall-versus-CPU split keeps optimization aimed at code that is actually costing something. Apart from the flame-graph trap, the module turns what was a specialist, third-party workflow into a standard part of the debugging toolkit.

  • #python
  • #profiling
  • #debugging
  • #performance
  • #cpython

Related posts