René's URL Explorer Experiment


Title: email: generating messages got slower after gh-87720, since folding walks the parse tree repeatedly · Issue #160675 · python/cpython · GitHub

Open Graph Title: email: generating messages got slower after gh-87720, since folding walks the parse tree repeatedly · Issue #160675 · python/cpython

X Title: email: generating messages got slower after gh-87720, since folding walks the parse tree repeatedly · Issue #160675 · python/cpython

Description: Bug report Bug description: The performance regression suite I run against CPython builds picked up a slowdown in email header folding after #134271 (gh-87720). The fix itself is important, since it stops encoded words with specials from...

Open Graph Description: Bug report Bug description: The performance regression suite I run against CPython builds picked up a slowdown in email header folding after #134271 (gh-87720). The fix itself is important, since i...

X Description: Bug report Bug description: The performance regression suite I run against CPython builds picked up a slowdown in email header folding after #134271 (gh-87720). The fix itself is important, since i...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"email: generating messages got slower after gh-87720, since folding walks the parse tree repeatedly","articleBody":"# Bug report\n\n### Bug description:\n\nThe performance regression suite I run against CPython builds picked up a slowdown in `email` header folding after #134271 (gh-87720). The fix itself is important, since it stops encoded words with specials from losing their quoting when refolded, so the goal here is only to make the new check cheaper, with exactly the same output.\n\nThe new check calls `contains_token_type('vtext')` for most parts while folding, and that walks the whole subtree of the part every time. Parts that don't fit are then split and their subparts are walked again, so headers without any `vtext`, which is the common case, have their tree walked several times. For a 50-recipient `To` header that's about 3,000 calls over 1,500 tokens.\n\nIt shows up whenever new messages are generated, since every header gets folded:\n\n```python\nimport email.policy\nfrom email.message import EmailMessage\n\nPOLICY = email.policy.SMTP.clone(max_line_length=78)\n\nmessage = EmailMessage(policy=POLICY)\nmessage[\"From\"] = \"Orders \u003corders@example.com>\"\nmessage[\"To\"] = \", \".join(f\"Customer {i:02d} \u003ccustomer-{i:02d}@example.net>\" for i in range(50))\nmessage[\"Subject\"] = \"Your order has been processed\"\nmessage.set_content(\"Your order was processed successfully.\\n\")\nmessage.as_bytes(policy=POLICY)\n```\n\n`as_bytes()` time per message, before and after the change:\n\n| recipients | before | after |\n|---:|---:|---:|\n| 1 | 0.071 ms | 0.092 ms (+29%) |\n| 10 | 0.223 ms | 0.345 ms (+55%) |\n| 50 | 0.855 ms | 1.400 ms (+64%) |\n\nTo check this isn't just a microbenchmark, I also ran a more realistic workload: 2,000 generated messages with a mix of 1 to 50 recipients, `Received`, `DKIM-Signature` and `List-Unsubscribe` headers, about 40% of them replies with `References`, and plain-text or HTML bodies. Generating and serializing them got about **17% slower** overall (+0.22 ms per message). Re-serializing parsed messages is barely affected (about +2%), since unchanged headers keep their original lines.\n\nThis only affects messages using the new policies (`EmailMessage`, `policy.default`, `policy.SMTP`, also through `smtplib.send_message()`). Messages using `compat32` go through the old folding code and aren't affected.\n\nThis isn't specific to any platform. The numbers above are local (arm64), and I validated the same on AWS Lambda, where a 50-recipient serialization was about 64% slower on 3.12 (arm64, PGO+LTO). The change is now in 3.12, 3.13, 3.14 and main.\n\nI think the repeated walks can be avoided without changing the result. A part can only contain `vtext` if the whole tree does, so the tree can be checked once per header and the per-part check skipped when there is none. When there is, the per-part check can walk the tree iteratively instead of with a recursive method call per token. With that, the realistic workload goes from +17% to about +6%, the 50-recipient case from +64% to about +18%, and headers that do contain encoded words stay as fast as they are now.\n\nThe folded output stays byte-for-byte identical to the current code (I compared the benchmark messages, the realistic workload and a few hundred foldings with encoded words, specials, quoted strings and comments), and `test_email` passes on main, 3.12 and 3.13. Happy to send a PR. cc @bitdancer\n\n### CPython versions tested on:\n\n3.12, 3.13, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n","author":{"url":"https://github.com/leandrodamascena","@type":"Person","name":"leandrodamascena"},"datePublished":"2026-10-25T18:09:57Z","url":"https://github.com/python/cpython/issues/160675"}

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:93184531-2bee-b580-45dc-e2dcbc004488
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE15A:136CDA:1DA7485:272BCD7:6B022F4B
html-safe-nonce07fe0a0eedc283f1db570774948be013c04984f1440de93b674fd604ed8e29fd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTVBOjEzNkNEQToxREE3NDg1OjI3MkJDRDc6NkIwMjJGNEIiLCJ2aXNpdG9yX2lkIjoiMjM2MzU3OTg3ODQxMjAwNTE5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac63e64de7f886003519814a514b14fcf257ee2545d7080fc0bfc6fdbe832f260b
hovercard-subject-tagissue:6027641020
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/160675/issue_layout
twitter:imagehttps://opengraph.githubassets.com/16b7fe98cab495fccab0ed2ea39bb562b0443f2bd8fade3523b789af023a8b3c/python/cpython/issues/160675
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/16b7fe98cab495fccab0ed2ea39bb562b0443f2bd8fade3523b789af023a8b3c/python/cpython/issues/160675
og:image:altBug report Bug description: The performance regression suite I run against CPython builds picked up a slowdown in email header folding after #134271 (gh-87720). The fix itself is important, since i...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameleandrodamascena
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/160675#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F160675
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%2F160675
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/160675
Reloadhttps://github.com/python/cpython/issues/160675
Reloadhttps://github.com/python/cpython/issues/160675
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/160675
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/160675
email: generating messages got slower after gh-87720, since folding walks the parse tree repeatedlyhttps://github.com/python/cpython/issues/160675#top
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
https://github.com/leandrodamascena
leandrodamascenahttps://github.com/leandrodamascena
on Oct 25, 2026https://github.com/python/cpython/issues/160675#issue-6027641020
#134271https://github.com/python/cpython/pull/134271
gh-87720https://github.com/python/cpython/issues/87720
@bitdancerhttps://github.com/bitdancer
eendebakpthttps://github.com/eendebakpt
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 Oct 25, 2026https://github.com/python/cpython/issues/160675#event-34197202715
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/160675
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/160675
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
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.