René's URL Explorer Experiment


Title: BlocksOutputBuffer causes a performance regression in bz2, lzma and zlib modules · Issue #101260 · python/cpython · GitHub

Open Graph Title: BlocksOutputBuffer causes a performance regression in bz2, lzma and zlib modules · Issue #101260 · python/cpython

X Title: BlocksOutputBuffer causes a performance regression in bz2, lzma and zlib modules · Issue #101260 · python/cpython

Description: Bug report The _BlocksOutputBuffer was introduced for all compression modules (bz2, lzma and zlib) in python 3.10 #21740 . It performs well on its advertised quality: speedy and memory efficient creation of very large in-memory blocks. H...

Open Graph Description: Bug report The _BlocksOutputBuffer was introduced for all compression modules (bz2, lzma and zlib) in python 3.10 #21740 . It performs well on its advertised quality: speedy and memory efficient cr...

X Description: Bug report The _BlocksOutputBuffer was introduced for all compression modules (bz2, lzma and zlib) in python 3.10 #21740 . It performs well on its advertised quality: speedy and memory efficient cr...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"BlocksOutputBuffer causes a performance regression in bz2, lzma and zlib modules","articleBody":"\u003c!--\r\n  If you're new to Python and you're not sure whether what you're experiencing is a bug, the CPython issue tracker is not\r\n  the right place to seek help. Consider the following options instead:\r\n\r\n  - reading the Python tutorial: https://docs.python.org/3/tutorial/\r\n  - posting in the \"Users\" category on discuss.python.org: https://discuss.python.org/c/users/7\r\n  - emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list\r\n  - searching our issue tracker (https://github.com/python/cpython/issues) to see if\r\n    your problem has already been reported\r\n-->\r\n\r\n# Bug report\r\n\r\nThe _BlocksOutputBuffer was introduced for all compression modules (bz2, lzma and zlib)  in python 3.10 https://github.com/python/cpython/pull/21740 . \r\n\r\nIt performs well on its advertised quality: speedy and memory efficient creation of very large in-memory blocks.\r\n\r\nHowever it came at the cost of: \r\n- Lots of extra code\r\n- A performance regression in the common use case\r\n\r\nThe common use case is small things in memory. Having large in-memory buffers (multiple gigabytes) is an anti-pattern and streaming interfaces should be used instead. Which in turn utilize small buffers.\r\n\r\nFor a small buffer the BlocksOutputBuffer needs to create a list and a bytes object, while the 3.9 method only creates the bytes object. When the initial bytes object is too small, the blocksoutputbuffer creates another bytes object and resizes the list. The 3.9 method simply resizes the bytes object.\r\nThe 3.9 method does not scale well beyond a large number of resizings while the BlocksOutputBuffer does (due to cost amortization in the list resize and the fact that it doesn't resize bytes objects, saving on memcpy) but this only applies to very large buffers, and these should be rare.\r\n\r\nThis can be shown by removing the blocksoutputbuffer and reverting to the 3.9 method of arranging the output buffer. I have made a branch here https://github.com/rhpvorderman/cpython/tree/noblocks .\r\n\r\nMicrobenchmarks. Taking current README.rst (10044 bytes) and compressing with compression level 1.\r\nBlocksoutputBuffer\r\n```\r\n$ ./python -m pyperf timeit -s 'data=open(\"README.rst\", \"rb\").read(); from zlib import compress' 'compress(data, level=1)'\r\n.....................\r\nMean +- std dev: 180 us +- 1 us\r\n```\r\narrange_output_buffer:\r\n```\r\n$ ./python -m pyperf timeit -s 'data=open(\"README.rst\", \"rb\").read(); from zlib import compress' 'compress(data, level=1)'\r\n.....................\r\nMean +- std dev: 174 us +- 1 us\r\n```\r\nAlso when taking a larger file Lib/_pydecimal.py (229220 uncompressed, 60974 bytes compressed) which certainly requires resizing the initial 16K buffer.\r\nBlocksOutputBuffer:\r\n```\r\n$ ./python -m pyperf timeit -s 'data=open(\"Lib/_pydecimal.py\", \"rb\").read(); from zlib import compress' 'compress(data, level=1)'\r\n.....................\r\nMean +- std dev: 2.37 ms +- 0.01 ms\r\n```\r\narrange_output_buffer\r\n```\r\n./python -m pyperf timeit -s 'data=open(\"Lib/_pydecimal.py\", \"rb\").read(); from zlib import compress' 'compress(data, level=1)'\r\n.....................\r\nMean +- std dev: 2.28 ms +- 0.01 ms\r\n```\r\nQ.E.D. BlocksOutputBuffer always loses against simple byte resizing for smaller buffers. _pydecimal.py is more than 200K so that is already quite a big input.\r\n\r\nAdditionally: \r\n```\r\n Modules/zlibmodule.c | 417 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------------\r\n 1 file changed, 117 insertions(+), 300 deletions(-)\r\n```\r\nAnd this is not counting the removal of the extra header file that provides the BlocksOutputBuffer.\r\n\r\nThe BlocksOutputBuffer is a nice piece of work when taken in isolation, but it optimizes for the pathological case rather than the common case. It is detrimental to the common case and it requires a lot of extra code that needs to be maintained.\r\n\r\nIf there are some issues with slow performance on larger buffers with arrange_output_buffer, I think several optimizations can still be done which are not as invasive as the _BlocksOutputBufer. For instance when zlib.decompress is called on a 100MB object, it makes sense to start the output buffer at 100MB rather than at 16K (default in 3.9). This severely limits the amount of resizes required. The same goes for zlib.compress. If the input is 100MB the maximum output is going to be maximally 100MB+header and trailer size. Reserving 100MB first and then downscaling to the compressed size (say 20MB) is much quicker than resizing a 16K buffer to 20MB using doublings only. \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-101279\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/rhpvorderman","@type":"Person","name":"rhpvorderman"},"datePublished":"2023-01-23T14:33:56Z","url":"https://github.com/python/cpython/issues/101260"}

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:6e0da3d8-cfef-b505-3c7e-231804753c4a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC2B0:1AE20C:3BAC6EF:4B9096E:6B01F9F1
html-safe-nonced1a004b142f4e7e9bd95e1b31031f2507de7cf3b1252720731c6818ba65efafc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMkIwOjFBRTIwQzozQkFDNkVGOjRCOTA5NkU6NkIwMUY5RjEiLCJ2aXNpdG9yX2lkIjoiMzQ5MjE5Nzg0MjQyMjk4NzI0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac700c7676fc077f4dce610035650da623cca60016c2051f154e23b070538271d0
hovercard-subject-tagissue:1553207186
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/101260/issue_layout
twitter:imagehttps://opengraph.githubassets.com/99d3d112e97c9affda82775f0eff70afda03d5bee7cf65022ec9081cdd0747ef/python/cpython/issues/101260
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/99d3d112e97c9affda82775f0eff70afda03d5bee7cf65022ec9081cdd0747ef/python/cpython/issues/101260
og:image:altBug report The _BlocksOutputBuffer was introduced for all compression modules (bz2, lzma and zlib) in python 3.10 #21740 . It performs well on its advertised quality: speedy and memory efficient cr...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerhpvorderman
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/101260#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F101260
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%2F101260
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/101260
Reloadhttps://github.com/python/cpython/issues/101260
Reloadhttps://github.com/python/cpython/issues/101260
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/101260
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/101260
BlocksOutputBuffer causes a performance regression in bz2, lzma and zlib moduleshttps://github.com/python/cpython/issues/101260#top
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
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
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/rhpvorderman
rhpvordermanhttps://github.com/rhpvorderman
on Jan 23, 2023https://github.com/python/cpython/issues/101260#issue-1553207186
#21740https://github.com/python/cpython/pull/21740
https://github.com/rhpvorderman/cpython/tree/noblockshttps://github.com/rhpvorderman/cpython/tree/noblocks
gh-101260: Return to a simpler output buffer for zlib, bz2 and lzma for better performance. #101279https://github.com/python/cpython/pull/101279
rhpvordermanhttps://github.com/rhpvorderman
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Jan 23, 2023https://github.com/python/cpython/issues/101260#event-8334869577
AlexWaygoodhttps://github.com/AlexWaygood
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
on Jan 23, 2023https://github.com/python/cpython/issues/101260#event-8335015214
https://github.com/rhpvorderman
rhpvordermanhttps://github.com/rhpvorderman
on Jan 24, 2023https://github.com/python/cpython/issues/101260#issuecomment-1401592825
https://github.com/rhpvorderman
rhpvordermanhttps://github.com/rhpvorderman
on Mar 21, 2023https://github.com/python/cpython/issues/101260#issuecomment-1477591367
arhadthedevhttps://github.com/arhadthedev
Compression issues 🗜https://github.com/orgs/python/projects/20
on Apr 1, 2023https://github.com/python/cpython/issues/101260#event-15225232096
https://github.com/arhadthedev
arhadthedevhttps://github.com/arhadthedev
on Apr 1, 2023https://github.com/python/cpython/issues/101260#issuecomment-1492829875
@Yhg1shttps://github.com/Yhg1s
@gpsheadhttps://github.com/gpshead
@animalizehttps://github.com/animalize
gh-21740https://github.com/python/cpython/pull/21740
https://github.com/rhpvorderman
rhpvordermanhttps://github.com/rhpvorderman
on May 11, 2023https://github.com/python/cpython/issues/101260#issuecomment-1543358757
rhpvordermanhttps://github.com/rhpvorderman
on May 11, 2023https://github.com/python/cpython/issues/101260#event-9218109880
Merge branch 'main' into pythongh-101260https://github.com/rhpvorderman/cpython/commit/741bb89b59e60673f1a3cf69a5b4ff536b0f10ce
pythongh-101260https://github.com/python/cpython/issues/101260
741bb89https://github.com/rhpvorderman/cpython/commit/741bb89b59e60673f1a3cf69a5b4ff536b0f10ce
Merge remote-tracking branch 'upstream/main' into pythongh-101260https://github.com/rhpvorderman/cpython/commit/b12be9be975424b18c0547a5d35755b28ca9bde8
pythongh-101260https://github.com/python/cpython/issues/101260
b12be9bhttps://github.com/rhpvorderman/cpython/commit/b12be9be975424b18c0547a5d35755b28ca9bde8
https://github.com/gpshead
gpsheadhttps://github.com/gpshead
on May 11, 2023https://github.com/python/cpython/issues/101260#issuecomment-1543429431
pyperformancehttps://github.com/python/pyperformance
#101279https://github.com/python/cpython/pull/101279
#101279https://github.com/python/cpython/pull/101279
https://github.com/rhpvorderman
rhpvordermanhttps://github.com/rhpvorderman
on May 12, 2023https://github.com/python/cpython/issues/101260#issuecomment-1545771804
@gpsheadhttps://github.com/gpshead
@animalizehttps://github.com/animalize
iritkatrielhttps://github.com/iritkatriel
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
on Nov 26, 2023https://github.com/python/cpython/issues/101260#event-11064202411
https://github.com/StanFromIreland
StanFromIrelandhttps://github.com/StanFromIreland
on Oct 15, 2025https://github.com/python/cpython/issues/101260#issuecomment-3408028507
StanFromIrelandhttps://github.com/StanFromIreland
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
pendingThe issue will be closed if no feedback is providedhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22pending%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
on Oct 15, 2025https://github.com/python/cpython/issues/101260#event-20304240903
https://github.com/emmatyping
emmatypinghttps://github.com/emmatyping
on Oct 16, 2025https://github.com/python/cpython/issues/101260#issuecomment-3413275162
#139976https://github.com/python/cpython/pull/139976
emmatypinghttps://github.com/emmatyping
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Oct 16, 2025https://github.com/python/cpython/issues/101260#event-20331129328
github-project-automationhttps://github.com/apps/github-project-automation
Compression issues 🗜https://github.com/orgs/python/projects/20
on Oct 16, 2025https://github.com/python/cpython/issues/101260
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/101260
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/101260
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
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
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
Compression issues 🗜https://github.com/orgs/python/projects/20
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.