René's URL Explorer Experiment


Title: gh-151378: Fix unbounded memory growth when recording binary and the thread is sleeping by maurycy · Pull Request #152089 · python/cpython · GitHub

Open Graph Title: gh-151378: Fix unbounded memory growth when recording binary and the thread is sleeping by maurycy · Pull Request #152089 · python/cpython

X Title: gh-151378: Fix unbounded memory growth when recording binary and the thread is sleeping by maurycy · Pull Request #152089 · python/cpython

Description: Fixes #151378 I've described the root cause in #151378. Instead of adding some LIMIT and checking it, I'm doing two tricks here that spare us one struct and some complexity: using a fixed buffer (lazy alloc, so threads do not pay any price if there's no repeats), instead of a dynamic array, and eager encoding, instead of having PendingRLESample. Truth be told, it's not easy to write a test. We currently have no test for any OverflowError Also, I'm wondering if we couldn't simplify alloc-dealloc in the reader, too: cpython/Modules/_remote_debugging/binary_io_reader.c Lines 1098 to 1114 in ee78d43 if (i == 0 || status != batch_status) { if (timestamps_list) { int rc = emit_batch(state, collector, thread_id, interpreter_id, batch_status, ts->current_stack, ts->current_stack_depth, reader, timestamps_list, batch_idx); Py_DECREF(timestamps_list); if (rc < 0) { return -1; } } timestamps_list = PyList_New(count - i); if (!timestamps_list) { return -1; } batch_status = status; batch_idx = 0; } cpython/Modules/_remote_debugging/binary_io_reader.c Line 958 in ee78d43 if (PyList_SetSlice(timestamps_list, actual_size, PyList_GET_SIZE(timestamps_list), NULL) < 0) { but it's out of the current scope (and maybe PyList_New(run_len) would be sufficient there; just call it a day.) (No) reproduction The same as in #151378 2026-06-24T15:42:07.243116000+0200 maurycy@gimel /Users/maurycy/work/cpython (rle-overlow-fixed ee78d43+) % ./python.exe -c " import time time.sleep(3600) " & TARGET=$! sudo ./python.exe -m profiling.sampling attach --binary -r 1000khz -d 300 -o /tmp/rle.bin $TARGET & sleep 2; PROF=$(pgrep -fn "profiling.sampling attach") for i in $(seq 5); do printf "t=-min RSS=%d MB\n" $i $(($(ps -o rss= -p $PROF|tr -d ' ')/1024)); sleep 60; done [1] 65625 [2] 65626 t= 1min RSS=32 MB t= 2min RSS=33 MB t= 3min RSS=33 MB t= 4min RSS=33 MB t= 5min RSS=33 MB Captured 99,316,092 samples in 300.00 seconds Sample rate: 331,053.64 samples/sec Error rate: 0.00 Binary Encoding: Records: 12,131 RLE repeat: 12,130 (100.0%) [99,308,159 samples] Full stack: 1 (0.0%) Suffix match: 0 (0.0%) Pop-push: 0 (0.0%) Frame Efficiency: Frames written: 1 Frames saved: 99,308,159 (100.0%) Bytes (pre-zstd): 189.6 MB Warning: missed 200683909 samples from the expected total of 300000001 (66.89%) Binary profile written to /tmp/rle.bin (99316092 samples) [2] + done sudo ./python.exe -m profiling.sampling attach --binary -r 1000khz -d 300 -o 2026-06-24T15:47:52.516465000+0200 maurycy@gimel /Users/maurycy/work/cpython (rle-overlow-fixed ee78d43+) % ./python.exe -VV Python 3.16.0a0 (heads/main-dirty:ee78d4323c1, Jun 24 2026, 12:32:26) [Clang 21.0.0 (clang-2100.1.1.101)] Issue: gh-151378

Open Graph Description: Fixes #151378 I've described the root cause in #151378. Instead of adding some LIMIT and checking it, I'm doing two tricks here that spare us one struct and some complexity: using a fixed b...

X Description: Fixes #151378 I&#39;ve described the root cause in #151378. Instead of adding some LIMIT and checking it, I&#39;m doing two tricks here that spare us one struct and some complexity: using a...

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

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:2ef66fc1-f7ed-9520-3ecc-63f98addc93d
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id8A34:1BC25C:3C71E2:50E87D:6B023B55
html-safe-nonce88d0015500c2e7860770b83a2d62efe54e5c793d86b0529108a6bb2e92ccba43
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTM0OjFCQzI1QzozQzcxRTI6NTBFODdEOjZCMDIzQjU1IiwidmlzaXRvcl9pZCI6IjI0NjQwNDc0OTU3MDIwMDI1MTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacef622188cf3d875ac93eb02c1e49c040d2300faed1f238d8174032ae841f9a03
hovercard-subject-tagpull_request:3928427222
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/python/cpython/pull/152089/files
twitter:imagehttps://avatars.githubusercontent.com/u/5383?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/5383?s=400&v=4
og:image:altFixes #151378 I've described the root cause in #151378. Instead of adding some LIMIT and checking it, I'm doing two tricks here that spare us one struct and some complexity: using a fixed b...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
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
disable-turbotrue
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

Links:

Skip to contenthttps://github.com/python/cpython/pull/152089/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F152089%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%2Fpython%2Fcpython%2Fpull%2F152089%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=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/152089/files
Reloadhttps://github.com/python/cpython/pull/152089/files
Reloadhttps://github.com/python/cpython/pull/152089/files
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
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
pablogsalhttps://github.com/pablogsal
python:mainhttps://github.com/python/cpython/tree/main
maurycy:rle-overlow-fixedhttps://github.com/maurycy/cpython/tree/rle-overlow-fixed
Conversation 10 https://github.com/python/cpython/pull/152089
Commits 8 https://github.com/python/cpython/pull/152089/commits
Checks 56 https://github.com/python/cpython/pull/152089/checks
Files changed https://github.com/python/cpython/pull/152089/files
Please reload this pagehttps://github.com/python/cpython/pull/152089/files
gh-151378: Fix unbounded memory growth when recording binary and the thread is sleeping https://github.com/python/cpython/pull/152089/files#top
Show all changes 8 commits https://github.com/python/cpython/pull/152089/files
266b8c4 eager encode, fixed buf maurycy Jun 24, 2026 https://github.com/python/cpython/pull/152089/commits/266b8c4a310ef0371cb07d91f1b39c958044f93a
25e079a lazy alloc maurycy Jun 24, 2026 https://github.com/python/cpython/pull/152089/commits/25e079ad7141e3c78bf69e79314485c6526ade1d
a2c1d59 nius maurycy Jun 24, 2026 https://github.com/python/cpython/pull/152089/commits/a2c1d594e2da81108fb8984163e9ee05ee7a6861
a628ae0 make -Wunused-function happy maurycy Jun 24, 2026 https://github.com/python/cpython/pull/152089/commits/a628ae0c07b43c1d194db380fe49f3595f709dda
160ff25 redundant new line maurycy Jun 24, 2026 https://github.com/python/cpython/pull/152089/commits/160ff256d075eb40085401a5d98407fd58bb74e3
a9449af up stale comment maurycy Jul 1, 2026 https://github.com/python/cpython/pull/152089/commits/a9449afb276b56a9825b54e75587ef7e093fee0b
497bc98 test maurycy Jul 1, 2026 https://github.com/python/cpython/pull/152089/commits/497bc989adf70639b3a7c4b1ac858d704591092e
edbea69 news rename maurycy Jul 4, 2026 https://github.com/python/cpython/pull/152089/commits/edbea694493b7adab4ad56960cb509202f54d267
Clear filters https://github.com/python/cpython/pull/152089/files
Please reload this pagehttps://github.com/python/cpython/pull/152089/files
Please reload this pagehttps://github.com/python/cpython/pull/152089/files
test_binary_format.py https://github.com/python/cpython/pull/152089/files#diff-bd4b914717c4ce7ddb2e29a91a71fdba550983ce9cea09b1ee06847b128d71b6
2026-06-24-16-40-15.gh-issue-151378.iYWa_6.rst https://github.com/python/cpython/pull/152089/files#diff-e73752dcd88ebb46f83d91d731248e06a1ed1afff144037028e34360b159e1e0
binary_io.h https://github.com/python/cpython/pull/152089/files#diff-d66bb62ae432ae35cdf9f80b4fc0e19d4058d1662f861b1557ffe3eebd483f61
binary_io_writer.c https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
module.c https://github.com/python/cpython/pull/152089/files#diff-9676fd8cee6e0d841f42f405a8e33a434fbebbc861207051571c97cef17c4108
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L568
Lib/test/test_profiling/test_sampling_profiler/test_binary_format.pyhttps://github.com/python/cpython/pull/152089/files#diff-bd4b914717c4ce7ddb2e29a91a71fdba550983ce9cea09b1ee06847b128d71b6
View file https://github.com/maurycy/cpython/blob/edbea694493b7adab4ad56960cb509202f54d267/Lib/test/test_profiling/test_sampling_profiler/test_binary_format.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/152089/{{ revealButtonHref }}
https://github.com/python/cpython/pull/152089/files#diff-bd4b914717c4ce7ddb2e29a91a71fdba550983ce9cea09b1ee06847b128d71b6
https://github.com/python/cpython/pull/152089/files#diff-bd4b914717c4ce7ddb2e29a91a71fdba550983ce9cea09b1ee06847b128d71b6
Misc/NEWS.d/next/Library/2026-06-24-16-40-15.gh-issue-151378.iYWa_6.rsthttps://github.com/python/cpython/pull/152089/files#diff-e73752dcd88ebb46f83d91d731248e06a1ed1afff144037028e34360b159e1e0
View file https://github.com/maurycy/cpython/blob/edbea694493b7adab4ad56960cb509202f54d267/Misc/NEWS.d/next/Library/2026-06-24-16-40-15.gh-issue-151378.iYWa_6.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/152089/{{ revealButtonHref }}
Please reload this pagehttps://github.com/python/cpython/pull/152089/files
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L336
Modules/_remote_debugging/binary_io.hhttps://github.com/python/cpython/pull/152089/files#diff-d66bb62ae432ae35cdf9f80b4fc0e19d4058d1662f861b1557ffe3eebd483f61
View file https://github.com/maurycy/cpython/blob/edbea694493b7adab4ad56960cb509202f54d267/Modules/_remote_debugging/binary_io.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/152089/{{ revealButtonHref }}
https://github.com/python/cpython/pull/152089/files#diff-d66bb62ae432ae35cdf9f80b4fc0e19d4058d1662f861b1557ffe3eebd483f61
https://github.com/python/cpython/pull/152089/files#diff-d66bb62ae432ae35cdf9f80b4fc0e19d4058d1662f861b1557ffe3eebd483f61
https://github.com/python/cpython/pull/152089/files#diff-d66bb62ae432ae35cdf9f80b4fc0e19d4058d1662f861b1557ffe3eebd483f61
https://github.com/python/cpython/pull/152089/files#diff-d66bb62ae432ae35cdf9f80b4fc0e19d4058d1662f861b1557ffe3eebd483f61
https://github.com/python/cpython/pull/152089/files#diff-d66bb62ae432ae35cdf9f80b4fc0e19d4058d1662f861b1557ffe3eebd483f61
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L336
Modules/_remote_debugging/binary_io_writer.chttps://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
View file https://github.com/maurycy/cpython/blob/edbea694493b7adab4ad56960cb509202f54d267/Modules/_remote_debugging/binary_io_writer.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/152089/{{ revealButtonHref }}
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
Please reload this pagehttps://github.com/python/cpython/pull/152089/files
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
Please reload this pagehttps://github.com/python/cpython/pull/152089/files
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/pull/152089/files#diff-0874163bd266558e3cba125b8511bf1614fcd01c94e99fc14d81daac38390847
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L336
Modules/_remote_debugging/module.chttps://github.com/python/cpython/pull/152089/files#diff-9676fd8cee6e0d841f42f405a8e33a434fbebbc861207051571c97cef17c4108
View file https://github.com/maurycy/cpython/blob/edbea694493b7adab4ad56960cb509202f54d267/Modules/_remote_debugging/module.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/152089/{{ revealButtonHref }}
https://github.com/python/cpython/pull/152089/files#diff-9676fd8cee6e0d841f42f405a8e33a434fbebbc861207051571c97cef17c4108
https://github.com/python/cpython/pull/152089/files#diff-9676fd8cee6e0d841f42f405a8e33a434fbebbc861207051571c97cef17c4108
Please reload this pagehttps://github.com/python/cpython/pull/152089/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.