René's URL Explorer Experiment


Title: Pure-Python pickle._Pickler can be significantly optimized · Issue #148706 · python/cpython · GitHub

Open Graph Title: Pure-Python pickle._Pickler can be significantly optimized · Issue #148706 · python/cpython

X Title: Pure-Python pickle._Pickler can be significantly optimized · Issue #148706 · python/cpython

Description: Feature or enhancement Proposal: Inspired by some of the optimization patterns used in #148700 , I took a look at the pure Python pickler and found some low-hanging fruit. Some of these changes do increase the complexity of maintaining t...

Open Graph Description: Feature or enhancement Proposal: Inspired by some of the optimization patterns used in #148700 , I took a look at the pure Python pickler and found some low-hanging fruit. Some of these changes do ...

X Description: Feature or enhancement Proposal: Inspired by some of the optimization patterns used in #148700 , I took a look at the pure Python pickler and found some low-hanging fruit. Some of these changes do ...

Opengraph URL: https://github.com/python/cpython/issues/148706

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Pure-Python pickle._Pickler can be significantly optimized","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nInspired by some of the optimization patterns used in #148700 , I took a look at the pure Python pickler and found some low-hanging fruit.  Some of these changes do increase the complexity of maintaining the code, but the double-digit performance gains might be worth it given `dill` and `cloudpickle` usage patterns.\n\nFYI, my testing showed 19-37% speed increase for `dill` so far.\n\nBelow is Opus's summary of the things *kept* in the PR I will be submitting. The PR includes microbenchmark experiments (`Misc/pickle-perf-diary.md`) for a much broader set of changes that did not survive.\n\n```\n  The pure-Python pickle._Pickler (Lib/pickle.py) is used as the fallback when\n  the _pickle C accelerator is unavailable and by code that explicitly\n  subclasses pickle.Pickler in Python. Its save() hot path currently does\n  more work than necessary relative to Modules/_pickle.c::save():\n\n  - the memo.get(id(obj)) and reducer_override probes run before the atomic-\n    type dispatch, so int / None / bool / float values pay for checks the\n    C reference implementation skips for these types;\n  - _batch_appends and _batch_setitems use itertools.batched() + enumerate()\n    even for exact list / dict instances, where the C accelerator's\n    batch_list_exact / batch_dict_exact skip that machinery;\n  - memoize() dispatches through put() to write a single MEMOIZE byte for\n    protocol >= 4 (the common case);\n  - save_long rebuilds the 2-byte BININT1 opcode via struct.pack on every\n    small-int save;\n  - framer.commit_frame() is invoked as a full method call per save() even\n    though the hot check is a single length compare;\n  - bytes values aren't in the save() dispatch fast path alongside str.\n\n  Attached patch addresses each of these with measured wins of -20% to -49%\n  on pure-Python _Pickler dump across a representative workload set\n  (list_of_ints, list_of_strs, dict of str->int, deep list, nested list of\n  dicts, list of short bytes, dict of bytes->int). Full CPython test suite,\n  dill 0.4.1, and cloudpickle 3.1.2 all pass / match baseline. Detailed\n  experiment ledger with raw bench data committed under\n  Misc/pickle-perf-diary.md and Misc/pickle-perf-data/ on the proposed\n  branch.\n```\n\nThere is notable user-facing change that can be addressed but I'd defer to reviewers on how important it is: atomic types no longer invoke reducer_override, wich actually aligns this with _pickle.c::save().\n\n### Has this already been discussed elsewhere?\n\nNo response given\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-148707\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/mjbommar","@type":"Person","name":"mjbommar"},"datePublished":"2026-04-18T00:26:19Z","url":"https://github.com/python/cpython/issues/148706"}

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/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:42b4dbcc-e984-956a-af54-ff36676db736
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEC68:2E124E:3DD9B1A:4EF2E61:6B021F3D
html-safe-nonce3423e64b973820e067cb8b3d296f4c93f53594c0c7594e786891c6c336d1fddb
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzY4OjJFMTI0RTozREQ5QjFBOjRFRjJFNjE6NkIwMjFGM0QiLCJ2aXNpdG9yX2lkIjoiNTgzMDU2MDM5ODM4MTgxNzY2MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac5ef04add531da96d3e2c1a6d47feb6e9d35c4789ad4c2870ab4000197642aed6
hovercard-subject-tagissue:4286054080
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/148706/issue_layout
twitter:imagehttps://opengraph.githubassets.com/70e673a36e67b182290ce550f6feaf369a0519387525d299da0eff1a55c91822/python/cpython/issues/148706
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/70e673a36e67b182290ce550f6feaf369a0519387525d299da0eff1a55c91822/python/cpython/issues/148706
og:image:altFeature or enhancement Proposal: Inspired by some of the optimization patterns used in #148700 , I took a look at the pure Python pickler and found some low-hanging fruit. Some of these changes do ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemjbommar
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/148706#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F148706
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%2Fpython%2Fcpython%2Fissues%2F148706
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/148706
Reloadhttps://github.com/python/cpython/issues/148706
Reloadhttps://github.com/python/cpython/issues/148706
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/148706
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/148706
Pure-Python pickle._Pickler can be significantly optimizedhttps://github.com/python/cpython/issues/148706#top
pendingThe issue will be closed if no feedback is providedhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22pending%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/mjbommar
mjbommarhttps://github.com/mjbommar
on Apr 18, 2026https://github.com/python/cpython/issues/148706#issue-4286054080
#148700https://github.com/python/cpython/pull/148700
gh-148706: Pure-Python pickle._Pickler can be significantly optimized #148707https://github.com/python/cpython/pull/148707
mjbommarhttps://github.com/mjbommar
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
on Apr 18, 2026https://github.com/python/cpython/issues/148706#event-24627872985
mjbommarhttps://github.com/mjbommar
on Apr 18, 2026https://github.com/python/cpython/issues/148706#event-24627925967
pythongh-148706: add NEWS entry for pickle._Pickler optimizationhttps://github.com/mjbommar/cpython/commit/4f0b43c2b6b47317cba7cf86f492791727031b72
pythongh-148706https://github.com/python/cpython/issues/148706
4f0b43chttps://github.com/mjbommar/cpython/commit/4f0b43c2b6b47317cba7cf86f492791727031b72
Add Misc/perf-work-summary.md — outcome record for the three shipped …https://github.com/mjbommar/cpython/commit/54fe7cb8dba846ccc20a17bb347dfb5821a81cd3
54fe7cbhttps://github.com/mjbommar/cpython/commit/54fe7cb8dba846ccc20a17bb347dfb5821a81cd3
https://github.com/serhiy-storchaka
serhiy-storchakahttps://github.com/serhiy-storchaka
on Apr 18, 2026https://github.com/python/cpython/issues/148706#issuecomment-4273193807
sergey-miryanovhttps://github.com/sergey-miryanov
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
on Apr 18, 2026https://github.com/python/cpython/issues/148706#event-24633910143
StanFromIrelandhttps://github.com/StanFromIreland
Pickle and copy issues 🥒https://github.com/orgs/python/projects/9
on Apr 18, 2026https://github.com/python/cpython/issues/148706#event-24634655462
StanFromIrelandhttps://github.com/StanFromIreland
pendingThe issue will be closed if no feedback is providedhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22pending%22
on Apr 18, 2026https://github.com/python/cpython/issues/148706#event-24634657304
https://github.com/mjbommar
mjbommarhttps://github.com/mjbommar
on Apr 18, 2026https://github.com/python/cpython/issues/148706#issuecomment-4273367972
https://pypistats.org/packages/cloudpicklehttps://pypistats.org/packages/cloudpickle
https://pypistats.org/packages/dillhttps://pypistats.org/packages/dill
mjbommarhttps://github.com/mjbommar
on Apr 18, 2026https://github.com/python/cpython/issues/148706#event-24643588815
pythongh-148706: add NEWS entry for pickle._Pickler optimizationhttps://github.com/mjbommar/cpython/commit/c55ec7b8dd40b43b31e7bf854a43b2f1e4f6eaa1
pythongh-148706https://github.com/python/cpython/issues/148706
c55ec7bhttps://github.com/mjbommar/cpython/commit/c55ec7b8dd40b43b31e7bf854a43b2f1e4f6eaa1
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Apr 21, 2026https://github.com/python/cpython/issues/148706#issuecomment-4288207490
https://github.com/mjbommar
mjbommarhttps://github.com/mjbommar
on Apr 21, 2026https://github.com/python/cpython/issues/148706#issuecomment-4288694849
uqfoundation/dill#485https://github.com/uqfoundation/dill/issues/485
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Apr 21, 2026https://github.com/python/cpython/issues/148706#issuecomment-4288750798
picnixzhttps://github.com/picnixz
not plannedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Apr 21, 2026https://github.com/python/cpython/issues/148706#event-24718510570
github-project-automationhttps://github.com/apps/github-project-automation
Pickle and copy issues 🥒https://github.com/orgs/python/projects/9
on Apr 21, 2026https://github.com/python/cpython/issues/148706
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/148706
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/148706
pendingThe issue will be closed if no feedback is providedhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22pending%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
Pickle and copy issues 🥒https://github.com/orgs/python/projects/9
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.