René's URL Explorer Experiment


Title: gh-150860: Skip the whitespace scan in json.loads() when there is none by gaborbernat · Pull Request #150861 · python/cpython · GitHub

Open Graph Title: gh-150860: Skip the whitespace scan in json.loads() when there is none by gaborbernat · Pull Request #150861 · python/cpython

X Title: gh-150860: Skip the whitespace scan in json.loads() when there is none by gaborbernat · Pull Request #150861 · python/cpython

Description: Decoding with json.loads() runs a whitespace-skipping regular expression at both ends of the document through the pure-Python decode() wrapper, on every call, before and after the C scanner does the real work. Almost all documents have no surrounding whitespace, so both matches scan nothing yet still pay for the call and a match-object allocation. For the small documents that dominate real traffic, that fixed overhead is a meaningful slice of the decode time. This skips the leading match when the document does not start with whitespace, and the trailing match when the parse already consumed the whole string. Documents that do have surrounding whitespace keep the original behavior, output is unchanged, and the wrapper stays in Python so the win applies to the default C-accelerated build. The effect is concentrated on small, whitespace-free documents (the common case). It costs a little on the rare document padded with both leading and trailing whitespace (one extra branch), and is neutral on large documents: Benchmark base patched loads tiny, no whitespace 469 ns 297 ns: 1.58x faster loads tiny, leading whitespace 473 ns 392 ns: 1.21x faster loads tiny, trailing whitespace 463 ns 400 ns: 1.16x faster loads tiny, both leading + trailing 473 ns 518 ns: 1.09x slower loads 4 KB / 32 KB / 100 KB, no whitespace — within noise (±2–3%) The large-document deltas sit inside run-to-run noise: the change only adds or removes work at the document boundaries, so it cannot scale with document size. A constant-overhead change measuring as a size-proportional regression is the signature of measurement noise on a contended machine, not a real cost. This overlaps with the broader rewrite in gh-117397 and is filed separately so the small, self-contained version can be judged on its own. It was split out of #150827, which now carries only the encoder change. Benchmark (pyperf) Run base vs patched by swapping Lib/json/decoder.py on the same interpreter. import json, pyperf def sized(target): n = target // 12 while True: s = json.dumps({str(i): i for i in range(n)}) if len(s) >= target: return s n += target // 24 PAYLOADS = { "no_ws_tiny": '{"a":1}', "leading_ws": ' {"a":1}', "trailing_ws": '{"a":1} ', "both_ws": ' {"a":1} ', "no_ws_4kb": sized(4*1024), "no_ws_32kb": sized(32*1024), "no_ws_100kb": sized(100*1024), } runner = pyperf.Runner() for name, payload in PAYLOADS.items(): runner.timeit(name=f"json_loads/{name}", stmt="loads(s)", setup=f"from json import loads; s = {payload!r}") Resolves #150860. Issue: gh-150860

Open Graph Description: Decoding with json.loads() runs a whitespace-skipping regular expression at both ends of the document through the pure-Python decode() wrapper, on every call, before and after the C scanner does th...

X Description: Decoding with json.loads() runs a whitespace-skipping regular expression at both ends of the document through the pure-Python decode() wrapper, on every call, before and after the C scanner does th...

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

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:6ec44cbf-b8d2-d62e-7ee9-399d0aa26ea4
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id8912:2454CC:3C75359:4CAAD3E:6B020A89
html-safe-nonce42c0f55f12f02bb2acacc41ab0e95f25e8eff730759210cb731cfb03e685686d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTEyOjI0NTRDQzozQzc1MzU5OjRDQUFEM0U6NkIwMjBBODkiLCJ2aXNpdG9yX2lkIjoiMTI3MTkyNDAxNjQwMzMxOTQzMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb3141d9d2f8f99f77e8b9cef87e64937f5429fa8ecf57a8c39b6e3b9afb7ea7f
hovercard-subject-tagpull_request:3796134054
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/150861/files
twitter:imagehttps://avatars.githubusercontent.com/u/690238?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/690238?s=400&v=4
og:image:altDecoding with json.loads() runs a whitespace-skipping regular expression at both ends of the document through the pure-Python decode() wrapper, on every call, before and after the C scanner does th...
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/150861/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F150861%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%2F150861%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/150861/files
Reloadhttps://github.com/python/cpython/pull/150861/files
Reloadhttps://github.com/python/cpython/pull/150861/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
gaborbernathttps://github.com/gaborbernat
python:mainhttps://github.com/python/cpython/tree/main
gaborbernat:opt/json-decode-skip-wshttps://github.com/gaborbernat/cpython/tree/opt/json-decode-skip-ws
Conversation 6 https://github.com/python/cpython/pull/150861
Commits 1 https://github.com/python/cpython/pull/150861/commits
Checks 102 https://github.com/python/cpython/pull/150861/checks
Files changed 2 https://github.com/python/cpython/pull/150861/files
gh-150860: Skip the whitespace scan in json.loads() when there is none https://github.com/python/cpython/pull/150861/files#top
Show all changes 1 commit https://github.com/python/cpython/pull/150861/files
2259760 gh-150860: Skip the whitespace scan in json.loads() when there is none gaborbernat Jun 3, 2026 https://github.com/python/cpython/pull/150861/commits/225976029a605816dfc14d51bb517c02ddf8e6ca
Clear filters https://github.com/python/cpython/pull/150861/files
Please reload this pagehttps://github.com/python/cpython/pull/150861/files
Please reload this pagehttps://github.com/python/cpython/pull/150861/files
decoder.py https://github.com/python/cpython/pull/150861/files#diff-33eeb72cd2a5669336ef86c3e349053e5eb034a222ef3f2365586ec3d3fe3037
2026-06-03-07-31-11.gh-issue-150860.8VbmHU.rst https://github.com/python/cpython/pull/150861/files#diff-00490ba32216e834c91d8ebb33f200d046621cea9dbb8c71ec4d5e183a3313bd
Lib/json/decoder.pyhttps://github.com/python/cpython/pull/150861/files#diff-33eeb72cd2a5669336ef86c3e349053e5eb034a222ef3f2365586ec3d3fe3037
View file https://github.com/gaborbernat/cpython/blob/225976029a605816dfc14d51bb517c02ddf8e6ca/Lib/json/decoder.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/150861/{{ revealButtonHref }}
https://github.com/python/cpython/pull/150861/files#diff-33eeb72cd2a5669336ef86c3e349053e5eb034a222ef3f2365586ec3d3fe3037
https://github.com/python/cpython/pull/150861/files#diff-33eeb72cd2a5669336ef86c3e349053e5eb034a222ef3f2365586ec3d3fe3037
Misc/NEWS.d/next/Library/2026-06-03-07-31-11.gh-issue-150860.8VbmHU.rsthttps://github.com/python/cpython/pull/150861/files#diff-00490ba32216e834c91d8ebb33f200d046621cea9dbb8c71ec4d5e183a3313bd
View file https://github.com/gaborbernat/cpython/blob/225976029a605816dfc14d51bb517c02ddf8e6ca/Misc/NEWS.d/next/Library/2026-06-03-07-31-11.gh-issue-150860.8VbmHU.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/150861/{{ revealButtonHref }}
Please reload this pagehttps://github.com/python/cpython/pull/150861/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.