Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
pablogsal merged 30 commits intopython:mainfrompablogsal:tachyon-opcodes
Dec 11, 2025

Conversation

@pablogsal
Copy link
Member

@pablogsalpablogsal commentedDec 7, 2025
edited
Loading

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_ATTRLOAD_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--opcodes to 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
screenrecording-2025-12-01_01-18-26.mp4

savannahostrowski, ivonastojanovic, chris-eibl, Sacul0457, and sergey-miryanov reacted with rocket emoji
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.

@pablogsalpablogsal marked this pull request as ready for reviewDecember 8, 2025 19:22
Copy link
Member

@savannahostrowskisavannahostrowski left a 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)!

This comment was marked as off-topic.

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
pablogsaland others added2 commitsDecember 9, 2025 19:13
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Copy link
Member

@savannahostrowskisavannahostrowski left a 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

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?

@pablogsalpablogsal added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelDec 10, 2025
@bedevere-bot
Copy link

🤖 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.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelDec 10, 2025
Copy link
Member

@StanFromIrelandStanFromIreland left a comment

Choose a reason for hiding this comment

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

Comment on lines 621 to 623
(taskgroups.__file__, 121, "TaskGroup._aexit", None),
(taskgroups.__file__, 72, "TaskGroup.__aexit__", None),
(script_name, 26, "main", None),

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?

Copy link
MemberAuthor

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

Comment on lines 666 to 668
(taskgroups.__file__, 121, "TaskGroup._aexit", None),
(taskgroups.__file__, 72, "TaskGroup.__aexit__", None),
(script_name, 26, "main", None),

Choose a reason for hiding this comment

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

Ditto.

Comment on lines 684 to 686
(taskgroups.__file__, 121, "TaskGroup._aexit", None),
(taskgroups.__file__, 72, "TaskGroup.__aexit__", None),
(script_name, 26, "main", None),

Choose a reason for hiding this comment

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

And here.

@pablogsal
Copy link
MemberAuthor

Some final notes.

Alsohttps://github.com/pablogsal/cpython/compare/tachyon-opcodes...StanFromIreland:cpython:tachyon-opcodes-jump?expand=1, but that can be done after.

Merged! Thanks a lot for that!

StanFromIreland reacted with heart emoji

Copy link
Member

@StanFromIrelandStanFromIreland left a 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.

pablogsaland others added2 commitsDecember 11, 2025 02:05
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@pablogsalpablogsal merged commit5b19c75 intopython:mainDec 11, 2025
46 checks passed
@pablogsalpablogsal deleted the tachyon-opcodes branchDecember 11, 2025 03:41
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@savannahostrowskisavannahostrowskisavannahostrowski approved these changes

@StanFromIrelandStanFromIrelandStanFromIreland approved these changes

@ivonastojanovicivonastojanovicAwaiting requested review from ivonastojanovic

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@pablogsal@StanFromIreland@bedevere-bot@savannahostrowski

[8]ページ先頭

©2009-2026 Movatter.jp