René's URL Explorer Experiment


Title: bpo-40255: Implement Immortal Instances - Optimization 2 by eduardo-elizondo · Pull Request #31489 · python/cpython · GitHub

Open Graph Title: bpo-40255: Implement Immortal Instances - Optimization 2 by eduardo-elizondo · Pull Request #31489 · python/cpython

X Title: bpo-40255: Implement Immortal Instances - Optimization 2 by eduardo-elizondo · Pull Request #31489 · python/cpython

Description: Immortalizing Runtime Heap After Startup This is an optimization on top of PR19474. The improvement here uses the assumption that everything that is alive after the runtime startup will (most likely) be alive during the entire lifecycle of the runtime. This then immortalizes the existing heap after the runtime has finished bootstrapping and right before the loading and execution of bytecode. Benchmark Results Overall: 0% slower compared to the main branch pyperformance results 2to3: Mean +- std dev: [cpython_master] 432 ms +- 15 ms -> [immortal_instances_opt2] 440 ms +- 12 ms: 1.02x slower chaos: Mean +- std dev: [cpython_master] 126 ms +- 4 ms -> [immortal_instances_opt2] 119 ms +- 3 ms: 1.06x faster float: Mean +- std dev: [cpython_master] 128 ms +- 4 ms -> [immortal_instances_opt2] 133 ms +- 6 ms: 1.04x slower go: Mean +- std dev: [cpython_master] 244 ms +- 10 ms -> [immortal_instances_opt2] 232 ms +- 8 ms: 1.05x faster hexiom: Mean +- std dev: [cpython_master] 11.5 ms +- 0.6 ms -> [immortal_instances_opt2] 11.3 ms +- 0.3 ms: 1.02x faster json_dumps: Mean +- std dev: [cpython_master] 19.2 ms +- 0.7 ms -> [immortal_instances_opt2] 19.7 ms +- 0.8 ms: 1.02x slower logging_format: Mean +- std dev: [cpython_master] 10.4 us +- 0.3 us -> [immortal_instances_opt2] 10.8 us +- 0.3 us: 1.04x slower logging_silent: Mean +- std dev: [cpython_master] 201 ns +- 8 ns -> [immortal_instances_opt2] 205 ns +- 7 ns: 1.02x slower logging_simple: Mean +- std dev: [cpython_master] 9.77 us +- 0.32 us -> [immortal_instances_opt2] 9.46 us +- 0.41 us: 1.03x faster meteor_contest: Mean +- std dev: [cpython_master] 164 ms +- 5 ms -> [immortal_instances_opt2] 161 ms +- 5 ms: 1.02x faster nbody: Mean +- std dev: [cpython_master] 163 ms +- 6 ms -> [immortal_instances_opt2] 159 ms +- 6 ms: 1.03x faster nqueens: Mean +- std dev: [cpython_master] 159 ms +- 5 ms -> [immortal_instances_opt2] 152 ms +- 6 ms: 1.05x faster pathlib: Mean +- std dev: [cpython_master] 28.5 ms +- 0.7 ms -> [immortal_instances_opt2] 28.2 ms +- 0.9 ms: 1.01x faster pickle: Mean +- std dev: [cpython_master] 16.0 us +- 0.5 us -> [immortal_instances_opt2] 15.7 us +- 0.8 us: 1.02x faster pickle_dict: Mean +- std dev: [cpython_master] 37.3 us +- 0.6 us -> [immortal_instances_opt2] 35.2 us +- 1.4 us: 1.06x faster pickle_list: Mean +- std dev: [cpython_master] 5.77 us +- 0.24 us -> [immortal_instances_opt2] 5.53 us +- 0.22 us: 1.04x faster pidigits: Mean +- std dev: [cpython_master] 284 ms +- 15 ms -> [immortal_instances_opt2] 276 ms +- 7 ms: 1.03x faster python_startup: Mean +- std dev: [cpython_master] 12.6 ms +- 0.4 ms -> [immortal_instances_opt2] 11.9 ms +- 0.5 ms: 1.05x faster python_startup_no_site: Mean +- std dev: [cpython_master] 8.89 ms +- 0.39 ms -> [immortal_instances_opt2] 8.21 ms +- 0.34 ms: 1.08x faster raytrace: Mean +- std dev: [cpython_master] 529 ms +- 16 ms -> [immortal_instances_opt2] 542 ms +- 15 ms: 1.03x slower regex_compile: Mean +- std dev: [cpython_master] 233 ms +- 6 ms -> [immortal_instances_opt2] 239 ms +- 6 ms: 1.03x slower regex_dna: Mean +- std dev: [cpython_master] 239 ms +- 6 ms -> [immortal_instances_opt2] 257 ms +- 6 ms: 1.08x slower regex_effbot: Mean +- std dev: [cpython_master] 4.53 ms +- 0.12 ms -> [immortal_instances_opt2] 4.69 ms +- 0.17 ms: 1.04x slower regex_v8: Mean +- std dev: [cpython_master] 33.2 ms +- 0.8 ms -> [immortal_instances_opt2] 34.4 ms +- 1.1 ms: 1.04x slower richards: Mean +- std dev: [cpython_master] 82.8 ms +- 3.7 ms -> [immortal_instances_opt2] 85.1 ms +- 3.5 ms: 1.03x slower scimark_fft: Mean +- std dev: [cpython_master] 571 ms +- 12 ms -> [immortal_instances_opt2] 614 ms +- 19 ms: 1.08x slower scimark_lu: Mean +- std dev: [cpython_master] 195 ms +- 6 ms -> [immortal_instances_opt2] 207 ms +- 6 ms: 1.06x slower scimark_monte_carlo: Mean +- std dev: [cpython_master] 116 ms +- 5 ms -> [immortal_instances_opt2] 119 ms +- 5 ms: 1.02x slower scimark_sor: Mean +- std dev: [cpython_master] 211 ms +- 6 ms -> [immortal_instances_opt2] 222 ms +- 8 ms: 1.05x slower scimark_sparse_mat_mult: Mean +- std dev: [cpython_master] 8.28 ms +- 0.40 ms -> [immortal_instances_opt2] 8.74 ms +- 0.36 ms: 1.06x slower sympy_expand: Mean +- std dev: [cpython_master] 878 ms +- 34 ms -> [immortal_instances_opt2] 853 ms +- 16 ms: 1.03x faster sympy_integrate: Mean +- std dev: [cpython_master] 35.2 ms +- 1.0 ms -> [immortal_instances_opt2] 35.7 ms +- 1.2 ms: 1.01x slower sympy_sum: Mean +- std dev: [cpython_master] 291 ms +- 13 ms -> [immortal_instances_opt2] 296 ms +- 6 ms: 1.02x slower sympy_str: Mean +- std dev: [cpython_master] 514 ms +- 11 ms -> [immortal_instances_opt2] 523 ms +- 14 ms: 1.02x slower unpack_sequence: Mean +- std dev: [cpython_master] 77.9 ns +- 2.3 ns -> [immortal_instances_opt2] 70.0 ns +- 2.0 ns: 1.11x faster unpickle: Mean +- std dev: [cpython_master] 21.5 us +- 0.7 us -> [immortal_instances_opt2] 22.1 us +- 1.1 us: 1.03x slower unpickle_pure_python: Mean +- std dev: [cpython_master] 463 us +- 17 us -> [immortal_instances_opt2] 447 us +- 7 us: 1.04x faster xml_etree_process: Mean +- std dev: [cpython_master] 102 ms +- 2 ms -> [immortal_instances_opt2] 98.2 ms +- 2.4 ms: 1.04x faster Benchmark hidden because not significant (13): deltablue, django_template, fannkuch, html5lib, json_loads, pickle_pure_python, pyflate, spectral_norm, telco, unpickle_list, xml_etree_parse, xml_etree_iterparse, xml_etree_generate Geometric mean: 1.00x slower Implementation Details To achieve this, in pymain_main we call the newly introduced internal API: _PyGC_ImmortalizeHeap. This uses the internal gc.freeze API to take all the existing objects in the heap and move them to the permanent generation. Then, it iterates the permanent generation marking all the containers as immortal, including the first traversal layer. Pseudo-Topological Ordered Finalization Due to this change, there will now be slight differences in the module finalization order due to the immortality of various instances. More specifically, at runtime shutdown, the modules that exist during __del__ will now change. Note that the behavior of __del__ during runtime shutdown is an implementation detail and clearly labeled undefined behavior by the official documentation. That being said, to reduce the variance introduced here by the runtime heap immortalization, we introduce a pseudo-topological order finalization of modules and its globals. Unfortunately, at runtime shutdown, we can’t fully guarantee the finalization dependency graph. Therefore, it does a best attempt at doing a topological finalization by executing the following heuristic: Start clearing from the newest to oldest User defined modules Finalize globals starting only with '_', excluding modules Finalize globals, excluding modules and __builtins__ Finalize the remaining objects excluding __builtins__ Start clearing from the newest to oldest Standard Library modules Finalize globals starting only with '_', excluding modules Finalize globals, excluding modules and __builtins__ Finalize the remaining objects excluding __builtins__ This ordering guarantees that for any user defined module, the entire standard library will still be available at runtime shutdown for any custom __del__ function. Not only that but it also keep the current flexibility of using underscores to have more control over the destruction of these objects during the shutdown of the runtime. The current heuristics can still be extended to provide a more well defined destruction ordered (i.e perhaps splitting stdlib between C modules and Lib modules). Test Output Checks A large portion of the tests that check __del__ behavior rely on using the subprocess module to execute and parse the result of a given python program after it exists. This change caused the behavior of subprocess stdout PIPE to change due. That is, if we don’t PIPE stdout, the output is correctly printed to the terminal. However, when using stdout PIPE the output is suppressed but not picked up by the subprocess module. To get around this, rather than using stdout to test the output of __del__, we use stderr which still behaves correctly even during the topological ordered destruction. Permanent Generation Finalization Currently the permanent generation is not cleaned up at runtime shutdown. This preserves that behavior but it could be extended to do a best effort destruction of these instances. https://bugs.python.org/issue40255

Open Graph Description: Immortalizing Runtime Heap After Startup This is an optimization on top of PR19474. The improvement here uses the assumption that everything that is alive after the runtime startup will (most likel...

X Description: Immortalizing Runtime Heap After Startup This is an optimization on top of PR19474. The improvement here uses the assumption that everything that is alive after the runtime startup will (most likel...

Opengraph URL: https://github.com/python/cpython/pull/31489

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/checks(.:format)
route-controllerpull_requests
route-actionchecks
fetch-noncev2:e6655a34-7b99-541e-1ae5-f7ce8bce97f4
current-catalog-service-hash87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a
request-id8888:2650A8:22C919:2DFE04:6969BFDF
html-safe-nonce2fabc7e4b56cc97e00926fe2552a98ac363c28ec6ecb14417ae08e2873c4a327
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODg4OjI2NTBBODoyMkM5MTk6MkRGRTA0OjY5NjlCRkRGIiwidmlzaXRvcl9pZCI6IjE4NjcyOTA4MjI2MTE5MjY3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacd4434d9afb8547788a734cecd90580ab5ffb0a57a5546cd1f4f10a93f4089cf5
hovercard-subject-tagpull_request:860048982
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/checks
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/31489/checks
twitter:imagehttps://avatars.githubusercontent.com/u/5315899?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/5315899?s=400&v=4
og:image:altImmortalizing Runtime Heap After Startup This is an optimization on top of PR19474. The improvement here uses the assumption that everything that is alive after the runtime startup will (most likel...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneacedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width full-width-p-0
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release83c08c21cdda978090dc44364b71aa5bc6dcea79
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/31489/checks#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F31489%2Fchecks
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F31489%2Fchecks
Sign up https://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%2Fchecks&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/31489/checks
Reloadhttps://github.com/python/cpython/pull/31489/checks
Reloadhttps://github.com/python/cpython/pull/31489/checks
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/31489/checks
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/pull/31489/checks
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
eduardo-elizondohttps://github.com/eduardo-elizondo
python:mainhttps://github.com/python/cpython/tree/main
eduardo-elizondo:immortal-references-opt2https://github.com/eduardo-elizondo/cpython/tree/immortal-references-opt2
Conversation 0 https://github.com/python/cpython/pull/31489
Commits 5 https://github.com/python/cpython/pull/31489/commits
Checks 0 https://github.com/python/cpython/pull/31489/checks
Files changed https://github.com/python/cpython/pull/31489/files
Please reload this pagehttps://github.com/python/cpython/pull/31489/checks
Please reload this pagehttps://github.com/python/cpython/pull/31489/checks
bpo-40255: Implement Immortal Instances - Optimization 2 https://github.com/python/cpython/pull/31489/checks#top
Please reload this pagehttps://github.com/python/cpython/pull/31489/checks
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.