Skip to content

gh-161676: Reduce perf trampoline overhead - #161677

Draft
pablogsal wants to merge 3 commits into
python:mainfrom
pablogsal:perf-trampoline-specialized-calls
Draft

pablogsal wants to merge 3 commits into
python:mainfrom
pablogsal:perf-trampoline-specialized-calls

Conversation

@pablogsal

@pablogsal pablogsal commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Two changes to reduce the -X perf overhead:

  1. Move the co_extra lookup out of py_trampoline_evaluator so it tail-calls the trampoline instead of keeping an extra native frame per call.
  2. Keep specialized calls and generator resumes when the PEP 523 hook is the perf trampoline. _PUSH_FRAME enters the frame through the hook, so perf still sees every Python frame.

Slowdown with -X perf relative to main without it (PGO + ThinLTO, Clang 21):

Benchmark main This PR
generators +234% +105%
generator_resumes +72% +62%
python_calls +50% +30%
scimark_lu +42% +35%
base32_small +11% +5%
json_loads +1% +2%
geometric mean (above) +55% +36%
pyperformance geomean (121) +11.9% +8.1%

No measurable change without -X perf.

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 9, 2026
@pablogsal pablogsal added the performance Performance or resource usage label Nov 9, 2026 — with ChatGPT Codex Connector
@pablogsal
pablogsal force-pushed the perf-trampoline-specialized-calls branch from 5afac8d to bd91c37 Compare November 9, 2026 17:49
@pablogsal pablogsal changed the title gh-161676: Reduce perf trampoline overhead gh-161676: Let the perf trampoline evaluator tail-call the trampoline Nov 9, 2026
@pablogsal pablogsal changed the title gh-161676: Let the perf trampoline evaluator tail-call the trampoline gh-161676: Reduce perf trampoline overhead Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance or resource usage type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant