René's URL Explorer Experiment


Title: Flatten Python eval loop with trampoline for reduced call overhead by youknowone · Pull Request #8431 · RustPython/RustPython · GitHub

Open Graph Title: Flatten Python eval loop with trampoline for reduced call overhead by youknowone · Pull Request #8431 · RustPython/RustPython

X Title: Flatten Python eval loop with trampoline for reduced call overhead by youknowone · Pull Request #8431 · RustPython/RustPython

Description: Summary Flatten the Python-to-Python call path so that CallPyExactArgs and CallBoundMethodExactArgs no longer recurse through new Rust stack frames. Instead, the bytecode loop returns a TailCall signal and a trampoline swaps frames in a single loop — matching CPython 3.12+'s approach. close youknowone#40 Changes Phase 0: Factor with_iframe Extract enter_iframe/exit_iframe from with_iframe with IframeEntryState struct No behavioral change — prepares composable pieces for the trampoline Phase 1: Datastack-allocated InterpreterFrame InterpreterFrame::new_on_datastack() bump-allocates both the InterpreterFrame and its LocalsPlus in a single datastack push release_datastack_frame() drops values and returns the base pointer for datastack_pop Phase 2–4: Trampoline loop + TailCall + exception propagation Add ExecutionResult::TailCall variant Add pending_tailcall_frame side channel on VirtualMachine Implement run_frame_fast_trampoline() with Vec stack tailcall_prepare_frame() builds callee frame on datastack and stores pointer Exception propagation via trampoline_handle_exception() — unwinds through suspended callers, attaches traceback entries Generators/coroutines and tracing fall back to recursive path Phase 5: Optimizations enter_iframe_unchecked skips recursion/C-stack checks in trampoline (already verified by specialization_call_recursion_guard) Move callable ownership from per-frame temporary_refs mutex to trampoline-local SuspendedFrame.owned_refs via VM side channel — eliminates mutex lock + Vec allocation per call Add TailCall support for CallBoundMethodExactArgs Move args directly from caller stack to callee fastlocals (no intermediate buffer) Read materialized pointer once in exit_iframe Safety PendingFrame wrapper for the tailcall side channel is fully private — the struct, its inner NonNull, and the Cell field are all non-pub. External code accesses only through set_pending_tailcall / take_pending_tailcall, preventing reuse of the unsafe Send+Sync impl elsewhere. Performance Metric Before (PR #8354) After Change Incremental call overhead ~55 ns ~35 ns -36% fib(28) ~178 ms ~137 ms -23% Measured on Apple Silicon. The remaining gap to the ≤30 ns target is addressable by InterpreterFrame hot/cold field splitting (separate work). Test coverage All existing tests pass: test_frame, test_traceback, test_generators, test_sys, test_pdb, test_exceptions, test_call, test_funcattrs, test_descr, test_faulthandler. Deep recursion (RecursionError), exception propagation through trampoline, sys._getframe() chain, and try/except across call boundaries all verified. Refs: youknowone#40 🤖 Generated with Claude Code Summary by CodeRabbit Performance Improved execution efficiency for Python functions and bound methods. Reduced overhead from function calls and execution-frame management. Improved handling of deep call chains for more stack-safe execution. Reliability Strengthened exception handling during complex execution flows. Improved coroutine and generator execution behavior. Enhanced cleanup and garbage collection during frame transitions.

Open Graph Description: Summary Flatten the Python-to-Python call path so that CallPyExactArgs and CallBoundMethodExactArgs no longer recurse through new Rust stack frames. Instead, the bytecode loop returns a TailCall si...

X Description: Summary Flatten the Python-to-Python call path so that CallPyExactArgs and CallBoundMethodExactArgs no longer recurse through new Rust stack frames. Instead, the bytecode loop returns a TailCall si...

Opengraph URL: https://github.com/RustPython/RustPython/pull/8431

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:b8babb4e-7d4e-4b72-9c69-6f0982c9ac53
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idDB0A:2BE220:2FEB61D:3FF1A3E:6B01E6BD
html-safe-nonceb5e283905b7102ae88b435dd99661555bcfc8cebf26cb2f328a011d5ba480248
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjBBOjJCRTIyMDoyRkVCNjFEOjNGRjFBM0U6NkIwMUU2QkQiLCJ2aXNpdG9yX2lkIjoiNjY2NDM1OTI2MTU5NTg4NzI5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacdf8602305bde36d46075eb6ac9f3c5efeebdf633ced6569fb497654cb15243c1
hovercard-subject-tagpull_request:4187149872
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/8431/files
twitter:imagehttps://avatars.githubusercontent.com/u/69878?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/69878?s=400&v=4
og:image:altSummary Flatten the Python-to-Python call path so that CallPyExactArgs and CallBoundMethodExactArgs no longer recurse through new Rust stack frames. Instead, the bytecode loop returns a TailCall si...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/RustPython/RustPython/pull/8431/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F8431%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F8431%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/pull/8431/files
Reloadhttps://github.com/RustPython/RustPython/pull/8431/files
Reloadhttps://github.com/RustPython/RustPython/pull/8431/files
RustPythonhttps://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Codehttps://github.com/RustPython/RustPython
Issues195 (195)https://github.com/RustPython/RustPython/issues
Pull requests133 (133)https://github.com/RustPython/RustPython/pulls
Discussionshttps://github.com/RustPython/RustPython/discussions
Actionshttps://github.com/RustPython/RustPython/actions
Projectshttps://github.com/RustPython/RustPython/projects
Wikihttps://github.com/RustPython/RustPython/wiki
Security and qualityhttps://github.com/RustPython/RustPython/security
Insightshttps://github.com/RustPython/RustPython/insights
Sign up for GitHub https://github.com/signup?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
youknowonehttps://github.com/youknowone
RustPython:mainhttps://github.com/RustPython/RustPython/tree/main
youknowone:flatten-eval-loophttps://github.com/youknowone/RustPython/tree/flatten-eval-loop
Conversation 43 https://github.com/RustPython/RustPython/pull/8431
Commits 10 https://github.com/RustPython/RustPython/pull/8431/commits
Checks 26 https://github.com/RustPython/RustPython/pull/8431/checks
Files changed https://github.com/RustPython/RustPython/pull/8431/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8431/files
Flatten Python eval loop with trampoline for reduced call overhead https://github.com/RustPython/RustPython/pull/8431/files#top
Show all changes 10 commits https://github.com/RustPython/RustPython/pull/8431/files
2fc29ce Factor with_iframe into enter_iframe/exit_iframe helpers youknowone Aug 1, 2026 https://github.com/RustPython/RustPython/pull/8431/commits/2fc29ced2f9a391bc973f7745b8c33fff4bd6787
b581c90 Allocate InterpreterFrame and LocalsPlus together on the datastack youknowone Aug 1, 2026 https://github.com/RustPython/RustPython/pull/8431/commits/b581c9007515358f1b10f4946e6bba33ac2dde1f
b089987 Implement trampoline loop for Python-to-Python calls youknowone Aug 1, 2026 https://github.com/RustPython/RustPython/pull/8431/commits/b089987cfabe8ec96492f2717888bee880ea797e
cdc0d32 Optimize trampoline: skip recursion check, avoid temporary_refs mutex… youknowone Aug 1, 2026 https://github.com/RustPython/RustPython/pull/8431/commits/cdc0d32ed9d6b739b2a311ddc5fbe384c7608cea
d00c250 Use UnsafeCell for pending_tailcall_refs youknowone Aug 1, 2026 https://github.com/RustPython/RustPython/pull/8431/commits/d00c2506f08e54764589fac844a716ac829fbeeb
e0fea23 Remove .claude/settings.json from tracking youknowone Aug 1, 2026 https://github.com/RustPython/RustPython/pull/8431/commits/e0fea234d2b07aeed470eafd39d8dce8beec4326
80028a8 Replace SendPtr with Option for type-safe pending tailcall youknowone Aug 2, 2026 https://github.com/RustPython/RustPython/pull/8431/commits/80028a80a68c74c4a359240d21cb75d8750e52ae
0bb5668 Restrict PendingFrame to private, expose only set/take methods youknowone Aug 2, 2026 https://github.com/RustPython/RustPython/pull/8431/commits/0bb5668d30ae58b3a6eca770745ad2a852fb2a17
a561f48 Restore C-stack overflow check in trampoline enter_iframe_unchecked youknowone Aug 2, 2026 https://github.com/RustPython/RustPython/pull/8431/commits/a561f48367935ad2ae01c7f4019ee3c402107440
a2e9a49 Address code review: entry frame double-free, panic safety, cleanup youknowone Aug 2, 2026 https://github.com/RustPython/RustPython/pull/8431/commits/a2e9a49e70380a79172b2f63c02ecde096f87f28
Clear filters https://github.com/RustPython/RustPython/pull/8431/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8431/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8431/files
settings.json https://github.com/RustPython/RustPython/pull/8431/files#diff-f27ac6f39d89fe021c56900069198aa7d9968f2cd6645c00b11ffd1b78fcf546
function.rs https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
coroutine.rs https://github.com/RustPython/RustPython/pull/8431/files#diff-d340edfa654334043dbe24788ce03de191ca484a34ae73e24ffb582575310bc0
frame.rs https://github.com/RustPython/RustPython/pull/8431/files#diff-03f2741d7d424014f3d2f0c82226be52fa58134aab34bf0780714ee67a248deb
mod.rs https://github.com/RustPython/RustPython/pull/8431/files#diff-fe30ecf7c6b462e46e0874a55a05ea0edba83cefad5ac7a86e7137fa8f86ba74
thread.rs https://github.com/RustPython/RustPython/pull/8431/files#diff-0bfe10fdb30f1f6c60e31b36e738b86cd68863aeb8113c4c1eadec33e90caf8d
.claude/settings.jsonhttps://github.com/RustPython/RustPython/pull/8431/files#diff-f27ac6f39d89fe021c56900069198aa7d9968f2cd6645c00b11ffd1b78fcf546
View file https://github.com/RustPython/RustPython/blob/9dff4d3a99cd06cea8062ec8b3bff4cd3f712163/.claude/settings.json
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8431/files
crates/vm/src/builtins/function.rshttps://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
View file https://github.com/youknowone/RustPython/blob/a2e9a49e70380a79172b2f63c02ecde096f87f28/crates/vm/src/builtins/function.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8431/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
https://github.com/RustPython/RustPython/pull/8431/files#diff-42d321490bc76e3b57deebb41ff9815e8bbb7c976bb1b57a076d01f7bc347698
crates/vm/src/coroutine.rshttps://github.com/RustPython/RustPython/pull/8431/files#diff-d340edfa654334043dbe24788ce03de191ca484a34ae73e24ffb582575310bc0
View file https://github.com/youknowone/RustPython/blob/a2e9a49e70380a79172b2f63c02ecde096f87f28/crates/vm/src/coroutine.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8431/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8431/files#diff-d340edfa654334043dbe24788ce03de191ca484a34ae73e24ffb582575310bc0
https://github.com/RustPython/RustPython/pull/8431/files#diff-d340edfa654334043dbe24788ce03de191ca484a34ae73e24ffb582575310bc0
https://github.com/RustPython/RustPython/pull/8431/files#diff-d340edfa654334043dbe24788ce03de191ca484a34ae73e24ffb582575310bc0
https://github.com/RustPython/RustPython/pull/8431/files#diff-d340edfa654334043dbe24788ce03de191ca484a34ae73e24ffb582575310bc0
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8431/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8431/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.