Skip to content

gh-162711: Only record branch history when tier 2 is enabled - #162804

Merged
kumaraditya303 merged 1 commit into
python:mainfrom
kumaraditya303:gh-162711-branch-history-tier2
Dec 1, 2026
Merged

kumaraditya303 merged 1 commit into
python:mainfrom
kumaraditya303:gh-162711-branch-history-tier2

Conversation

@kumaraditya303

@kumaraditya303 kumaraditya303 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

In the free-threaded build the main thread's bytecode is stored inline in the code object, so the store done by RECORD_BRANCH_TAKEN on every conditional jump caused false sharing with other threads reading co_tlbc and _co_instrumentation_version when calling the same function.

The branch history is only used by the tier 2 optimizer, so only record it when _Py_TIER2 is defined.

In the free-threaded build the main thread's bytecode is stored inline
in the code object, so the store done by RECORD_BRANCH_TAKEN on every
conditional jump caused false sharing with other threads reading
co_tlbc and _co_instrumentation_version when calling the same function.

The branch history is only used by the tier 2 optimizer, so only record
it when _Py_TIER2 is defined.
@kumaraditya303
kumaraditya303 merged commit 44c154a into python:main Dec 1, 2026
72 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @kumaraditya303 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@kumaraditya303
kumaraditya303 deleted the gh-162711-branch-history-tier2 branch December 1, 2026 03:17
@bedevere-app

bedevere-app Bot commented Dec 1, 2026

Copy link
Copy Markdown

GH-162909 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Dec 1, 2026
kumaraditya303 added a commit that referenced this pull request Dec 1, 2026
…H-162804) (#162909)

gh-162711: Only record branch history when tier 2 is enabled (GH-162804)
(cherry picked from commit 44c154a)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants