Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-138122: Make the tachyon profiler opcode-aware#142394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Introduces LocationInfo struct sequence with end_lineno, col_offset, andend_col_offset fields. Adds opcodes parameter to RemoteUnwinder thatextracts the currently executing opcode alongside its source span.Refactors linetable parsing to correctly accumulate line numbersseparately from output values, fixing edge cases in computed_line.
New opcode_utils.py maps opcode numbers to names and detects specializedvariants using opcode module metadata. Adds normalize_location() andextract_lineno() helpers to collector base for uniform location handling.CLI gains --opcodes flag, validated against compatible formats (gecko,flamegraph, heatmap, live).
Stores per-node opcode counts in the tree structure. Exports opcodemapping (names and deopt relationships) in JSON so the JS renderer canshow instruction names and distinguish specialized variants.
Tracks opcode state transitions per thread and emits interval markerswhen the executing opcode changes. Markers include opcode name, line,column, and duration. Adds Opcodes category to marker schema.
Expandable panel per hot line shows instruction-level sample breakdownwith opcode names and specialization percentage. Converts call graphdata structures from lists to sets for O(1) deduplication.
New widget displays instruction-level stats for selected function when--opcodes is enabled. Navigation via j/k keys with scroll support.Adds per-thread opcode tracking. Updates pstats collector for new frameformat.
Frame location is now a 4-tuple (lineno, end_lineno, col_offset,end_col_offset). MockFrameInfo wraps locations in LocationInfo struct.Updates assertions throughout and adds opcode_utils coverage.
# Conflicts:#Lib/test/test_profiling/test_sampling_profiler/test_integration.py
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
savannahostrowski left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
First pass onmost of the files (mainly the JS/CSS)! I ended up playing around with this quite a bit (flamegraph, heatmap, live mode, etc) and it looks awesome. You're on a roll 💫 !
A couple of comments here and then I also openedpablogsal#110 to move a bunch of the CSS into proper classes instead of inlining all the styles, which fixes some dark mode theming bugs (figured that'd be simpler than commenting in a bunch of places)!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
CSS fixes for opcode-aware Tachyon -pythongh-138122
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
savannahostrowski left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Two small comments (and another CSS fix PR) but this looks good to me otherwise!
| python -m profiling.sampling run --opcodes --flamegraph script.py | ||
| This feature provides visibility into Python's bytecode execution, including | ||
| adaptive specialization optimizations. When a generic instruction like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Wondering if it's worth linking back tohttps://docs.python.org/3/whatsnew/3.11.html#whatsnew311-pep659, in case people want to learn more about the specializing adaptive interpreter?
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Savannah Ostrowski <savannah@python.org>
bedevere-bot commentedDec 10, 2025
🤖 New build scheduled with the buildbot fleet by@pablogsal for commitede0f79 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F142394%2Fmerge If you want to schedule another build, you need to add the🔨 test-with-buildbots label again. |
StanFromIreland left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Some final notes.
Alsohttps://github.com/pablogsal/cpython/compare/tachyon-opcodes...StanFromIreland:cpython:tachyon-opcodes-jump?expand=1, but that can be done after.
Lib/test/test_external_inspection.py Outdated
| (taskgroups.__file__, 121, "TaskGroup._aexit", None), | ||
| (taskgroups.__file__, 72, "TaskGroup.__aexit__", None), | ||
| (script_name, 26, "main", None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The line numbers are subject to change, why did you set them instead of usingANY like before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yeah, let me change the ones that are not profiling specific. Good catch
Lib/test/test_external_inspection.py Outdated
| (taskgroups.__file__, 121, "TaskGroup._aexit", None), | ||
| (taskgroups.__file__, 72, "TaskGroup.__aexit__", None), | ||
| (script_name, 26, "main", None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ditto.
Lib/test/test_external_inspection.py Outdated
| (taskgroups.__file__, 121, "TaskGroup._aexit", None), | ||
| (taskgroups.__file__, 72, "TaskGroup.__aexit__", None), | ||
| (script_name, 26, "main", None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
And here.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Fix shift when selecting
pablogsal commentedDec 10, 2025
Merged! Thanks a lot for that! |
StanFromIreland left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
I have a docs suggestion but feel free to disregard it.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
5b19c75 intopython:mainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
When profiling Python code, knowing which source line is hot often isn't enough—a single line can contain multiple operations with very different performance characteristics. For example, result = obj.attr + expensive_call() has an attribute load, a function call, and an addition, but traditional line-level profiling treats them identically. This becomes especially important with the adaptive specialization, where understanding whether the interpreter has specialized an instruction (e.g.,
LOAD_ATTR→LOAD_ATTR_INSTANCE_VALUE) provides crucial optimization insights that were previously only visible through manual dis inspection.This PR threads bytecode information through the existing sampling profiler infrastructure by extending RemoteUnwinder to optionally extract the executing opcode and its precise source span (including column offsets) from the remote process's frame state. The column-level location data flows through to the visualization layers, where the heatmap can highlight the exact expression within a line, the gecko format emits interval markers for Firefox Profiler's timeline, and the live TUI displays real-time instruction breakdowns. The feature is opt-in via
--opcodesto avoid the overhead when not needed, and the opcode utilities handle the mapping between specialized instruction variants and their base forms so users can see both what's actually executing and what it was specialized from.screenrecording-2025-12-02_21-12-36.mp4