René's URL Explorer Experiment


Title: Reduce TypeForm recognition slowdown by davidfstr · Pull Request #21585 · python/mypy · GitHub

Open Graph Title: Reduce TypeForm recognition slowdown by davidfstr · Pull Request #21585 · python/mypy

X Title: Reduce TypeForm recognition slowdown by davidfstr · Pull Request #21585 · python/mypy

Description: References #21262 Summary Enabling TypeForm by default (#21262) regressed mypy's self-check by ~2% on mypyc-compiled builds. Details The regression came entirely from SemanticAnalyzer.try_parse_as_type_expression, which is now invoked eagerly on ~2.84M expressions per self-check. Of those, ~3.3% reached the expensive full-parse block (expr_to_analyzed_type + isolated_error_analysis), and ~91% of those full parses failed — pure wasted work. This branch adds a series of fast-rejection filters to the offending function (SemanticAnalyzer.try_parse_as_type_expression), eliminating ~83% of the full-parse attempts (3,144 → 542) on mypy's self-check, with zero correctness regressions. End-to-end this recovers ~43% of the regression by paired median (21.6 ms of a 50.2 ms CPU-time regression, n=100, CI ±5 ms; consistent with ~34–40% on wall-clock). This branch also adds additional instrumentation to analyze what kinds of expressions pass through the fast-rejection filters and make it to a full-parse. This instrumentation is enabled via the MYPY_TYPEFORM_PROFILE_FULL_PARSE variable and outputs a .tsv file that can be processed using the new misc/analyze_typeform_full_parse_profile.py script to classify & aggregate expressions. Finally this branch extends misc/perf_compare.py with additional reporting options to reduce measured variance. Each commit on the PR branch has a detailed message giving more information about the specific changes made. Optimization Results CPU time — canonical; lowest-variance metric python misc/perf_compare.py --warmup-runs 3 --num-runs 100 -j 3 \ --metric cpu --workers1 \ 022d9bc96 16fef2515 HEAD Commit Mean Median Δ vs baseline (paired median ±95% CI) 022d9bc96 baseline 2.768 s 2.757 s — 16fef2515 regression 2.817 s 2.809 s +50.2 ms ±5.2 (+1.82%) 3f39cd753/HEAD branch (all filters) 2.797 s 2.789 s +28.6 ms ±5.5 (+1.04%) Details CPU time (user+sys) on a single worker is the lowest-variance estimator here (CV ≈ 3.3%, vs ≈ 7.5% for wall-clock at the same n) and the truest measure of the per-call work being attacked: with one worker the whole self-check runs serially, so all ~2.84M calls land in one CPU-time figure rather than being spread across workers and hidden behind the slowest one. The branch recovers 21.6 ms of the 50.2 ms regression — ~43% by paired median (~40% by trimmed mean), leaving +28.6 ms (~57%, still well outside the ±5 ms CI). The recovered fraction is the difference of two deltas measured against the same baseline within one interleaved run, so it inherits the run's low noise (a conservative independent-error bound is ≈ ±7.6 ms on the 21.6 ms numerator; the true band is tighter because the two deltas are positively correlated — same baseline, same per-round machine state). Wall-clock — default user-facing metric python misc/perf_compare.py --warmup-runs 3 --num-runs 100 -j 3 \ 022d9bc96 16fef2515 HEAD python misc/perf_compare.py --warmup-runs 3 --num-runs 400 -j 3 \ 022d9bc96 16fef2515 HEAD Run Commit Median Δ vs baseline (paired median ±95% CI) n=100 022d9bc96 baseline 1.342 s — 16fef2515 regression 1.369 s +27.2 ms ±6.7 (+2.03%) 3f39cd753 branch 1.357 s +16.3 ms ±6.0 (+1.21%) n=400 022d9bc96 baseline 1.351 s — 16fef2515 regression 1.369 s +17.6 ms ±3.3 (+1.30%) 3f39cd753 branch 1.362 s +11.6 ms ±3.0 (+0.86%) Details Wall-clock recovery is **~40% at n=100** (10.9 ms of 27.2 ms) and **~34% at n=400** (6.0 ms of 17.6 ms) by paired median — consistent with the CPU figure once you allow for wall-clock's higher variance and the fact that it is bounded by the slowest worker. The recovered fraction (~34–43% across metrics and run lengths) stays stable even though the absolute regression differs a lot between metrics (≈50 ms CPU vs ≈18–27 ms wall) — the reassuring sign that the recovery is real rather than a noise artifact. Using the new full-parse instrumentation Details # 1. Run instrumented self-check on this branch: MYPY_TYPEFORM_PROFILE_FULL_PARSE=/tmp/tf.log \ python -m mypy --config-file mypy_self_check.ini -p mypy --no-incremental # 2. Aggregate the profile: python misc/analyze_typeform_full_parse_profile.py --top 20 /tmp/tf.log.* Open Questions Is the MYPY_TYPEFORM_PROFILE_FULL_PARSE env-var name acceptable, or should it follow an existing naming convention? I did not run performance numbers against non-mypy repositories (like PyTorch and Black) as I originally planned. Would you like me to? Should the misc/perf_compare.py changes ship in this PR, or land separately? They are a general benchmarking-harness improvement (CPU metric, single-worker mode, median-based reporting, opt-in binary cache), independent of the TypeForm filters — splitting them into their own PR may be cleaner for review.

Open Graph Description: References #21262 Summary Enabling TypeForm by default (#21262) regressed mypy's self-check by ~2% on mypyc-compiled builds. Details The regression came entirely from SemanticAnalyzer.try_parse...

X Description: References #21262 Summary Enabling TypeForm by default (#21262) regressed mypy's self-check by ~2% on mypyc-compiled builds. Details The regression came entirely from SemanticAnalyzer.try_p...

Opengraph URL: https://github.com/python/mypy/pull/21585

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:08f23765-ea6d-6cd8-3465-a76b310f596b
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB160:8DE5B:844498:B1275E:6A4C48FD
html-safe-nonce82f08b6ed490df56dc3d919adf5c505e96d064ad80ff450192a98c1fe1827fce
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTYwOjhERTVCOjg0NDQ5ODpCMTI3NUU6NkE0QzQ4RkQiLCJ2aXNpdG9yX2lkIjoiMTIzNTE0NTU3MTQ4NTYzMjc2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace671ddf19703c8609cb0a4905531f16f72fbfb5ebfd7ef1fbb751cee0a471ec1
hovercard-subject-tagpull_request:3797228127
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/mypy/pull/21585/files
twitter:imagehttps://avatars.githubusercontent.com/u/764688?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/764688?s=400&v=4
og:image:altReferences #21262 Summary Enabling TypeForm by default (#21262) regressed mypy's self-check by ~2% on mypyc-compiled builds. Details The regression came entirely from SemanticAnalyzer.try_parse...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/mypy git https://github.com/python/mypy.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id7053637
octolytics-dimension-repository_nwopython/mypy
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id7053637
octolytics-dimension-repository_network_root_nwopython/mypy
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
release3996b3b83990e134be6c099ab9a7f48f140ae80f
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/mypy/pull/21585/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fpull%2F21585%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fpull%2F21585%2Ffiles
Sign up https://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%2Fmypy
Reloadhttps://github.com/python/mypy/pull/21585/files
Reloadhttps://github.com/python/mypy/pull/21585/files
Reloadhttps://github.com/python/mypy/pull/21585/files
Please reload this pagehttps://github.com/python/mypy/pull/21585/files
python https://github.com/python
mypyhttps://github.com/python/mypy
Please reload this pagehttps://github.com/python/mypy/pull/21585/files
Notifications https://github.com/login?return_to=%2Fpython%2Fmypy
Fork 3.2k https://github.com/login?return_to=%2Fpython%2Fmypy
Star 20.5k https://github.com/login?return_to=%2Fpython%2Fmypy
Code https://github.com/python/mypy
Issues 2.7k https://github.com/python/mypy/issues
Pull requests 460 https://github.com/python/mypy/pulls
Actions https://github.com/python/mypy/actions
Projects https://github.com/python/mypy/projects
Wiki https://github.com/python/mypy/wiki
Security and quality 0 https://github.com/python/mypy/security
Insights https://github.com/python/mypy/pulse
Code https://github.com/python/mypy
Issues https://github.com/python/mypy/issues
Pull requests https://github.com/python/mypy/pulls
Actions https://github.com/python/mypy/actions
Projects https://github.com/python/mypy/projects
Wiki https://github.com/python/mypy/wiki
Security and quality https://github.com/python/mypy/security
Insights https://github.com/python/mypy/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fmypy%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fmypy%2Fissues%2Fnew%2Fchoose
davidfstrhttps://github.com/davidfstr
python:masterhttps://github.com/python/mypy/tree/master
davidfstr:f/typeform_complete--take2https://github.com/davidfstr/mypy/tree/f/typeform_complete--take2
Conversation 12 https://github.com/python/mypy/pull/21585
Commits 8 https://github.com/python/mypy/pull/21585/commits
Checks 24 https://github.com/python/mypy/pull/21585/checks
Files changed https://github.com/python/mypy/pull/21585/files
Please reload this pagehttps://github.com/python/mypy/pull/21585/files
Reduce TypeForm recognition slowdown https://github.com/python/mypy/pull/21585/files#top
Show all changes 8 commits https://github.com/python/mypy/pull/21585/files
cb0ae01 misc/perf_compare.py: Add options/behaviors to reduce measured variance davidfstr Jun 3, 2026 https://github.com/python/mypy/pull/21585/commits/cb0ae01dcff8b685e8c7cf8ca3cde9c4ef856f5f
208f9b6 TypeForm: Add instrumentation of full parses done in semanal.py's try… davidfstr Jun 3, 2026 https://github.com/python/mypy/pull/21585/commits/208f9b62fbda19cf535640ca38a8523bcc3cdf8b
6fba903 TypeForm: Add 7 more early-reject filters to semanal.py's try_parse_a… davidfstr Jun 3, 2026 https://github.com/python/mypy/pull/21585/commits/6fba90341f00e24185cab03c5748ba110b171775
978e9b4 SQUISH -> misc/perf_compare.py -- Workaround inability to return Any … davidfstr Jun 3, 2026 https://github.com/python/mypy/pull/21585/commits/978e9b49a300ceeb8df10124d0b4df82976e58ea
5a03b13 SQUISH -> misc/perf_compare.py -- Workaround missing 'resource' modul… davidfstr Jun 3, 2026 https://github.com/python/mypy/pull/21585/commits/5a03b136514da99902ea0f6e2fba6c3f0d20a377
91052ef [pre-commit.ci] auto fixes from pre-commit.com hooks pre-commit-ci[bot] Jun 3, 2026 https://github.com/python/mypy/pull/21585/commits/91052ef56f02becab27ab524bedfd3cb10a00ed0
2b804d6 SQUISH -> misc/perf_compare.py -- typechecker fixes davidfstr Jun 3, 2026 https://github.com/python/mypy/pull/21585/commits/2b804d68f99b9e792822a2355682c2f9ab95226d
12f9335 SQUISH -> misc/perf_compare.py -- typechecker fixes, take 2 davidfstr Jun 3, 2026 https://github.com/python/mypy/pull/21585/commits/12f933518d94df3e5203731c9cc4f0136853496b
Clear filters https://github.com/python/mypy/pull/21585/files
Please reload this pagehttps://github.com/python/mypy/pull/21585/files
Please reload this pagehttps://github.com/python/mypy/pull/21585/files
.gitignore https://github.com/python/mypy/pull/21585/files#diff-bc37d034bad564583790a46f19d807abfe519c5671395fd494d8cce506c42947
analyze_typeform_full_parse_profile.py https://github.com/python/mypy/pull/21585/files#diff-6264c92e802ad62c7474034da3c2bf4fd432c700745137db08263ee38f536ad9
analyze_typeform_stats.py https://github.com/python/mypy/pull/21585/files#diff-c84e267d0f8adccb8e1fc2c9ee689161b5cea0cbd21706f119ed5c00a5243a36
perf_compare.py https://github.com/python/mypy/pull/21585/files#diff-ea4aea86b9b5f1bf04d4d6a98417afdaf4524d0f5d7278eac034bc079dc6a135
semanal.py https://github.com/python/mypy/pull/21585/files#diff-f782aad4853edceb67a88efe43d2869579d075a77b8e8dd2add91e818a9fa164
.gitignorehttps://github.com/python/mypy/pull/21585/files#diff-bc37d034bad564583790a46f19d807abfe519c5671395fd494d8cce506c42947
View file https://github.com/python/mypy/blob/12f933518d94df3e5203731c9cc4f0136853496b/.gitignore
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/mypy/pull/21585/{{ revealButtonHref }}
https://github.com/python/mypy/pull/21585/files#diff-bc37d034bad564583790a46f19d807abfe519c5671395fd494d8cce506c42947
misc/analyze_typeform_full_parse_profile.pyhttps://github.com/python/mypy/pull/21585/files#diff-6264c92e802ad62c7474034da3c2bf4fd432c700745137db08263ee38f536ad9
View file https://github.com/python/mypy/blob/12f933518d94df3e5203731c9cc4f0136853496b/misc/analyze_typeform_full_parse_profile.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/mypy/pull/21585/{{ revealButtonHref }}
misc/analyze_typeform_stats.pyhttps://github.com/python/mypy/pull/21585/files#diff-c84e267d0f8adccb8e1fc2c9ee689161b5cea0cbd21706f119ed5c00a5243a36
View file https://github.com/python/mypy/blob/12f933518d94df3e5203731c9cc4f0136853496b/misc/analyze_typeform_stats.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/mypy/pull/21585/{{ revealButtonHref }}
https://github.com/python/mypy/pull/21585/files#diff-c84e267d0f8adccb8e1fc2c9ee689161b5cea0cbd21706f119ed5c00a5243a36
https://github.com/python/mypy/pull/21585/files#diff-c84e267d0f8adccb8e1fc2c9ee689161b5cea0cbd21706f119ed5c00a5243a36
https://github.com/python/mypy/pull/21585/files#diff-c84e267d0f8adccb8e1fc2c9ee689161b5cea0cbd21706f119ed5c00a5243a36
https://github.com/python/mypy/pull/21585/files#diff-c84e267d0f8adccb8e1fc2c9ee689161b5cea0cbd21706f119ed5c00a5243a36
Please reload this pagehttps://github.com/python/mypy/pull/21585/files
Please reload this pagehttps://github.com/python/mypy/pull/21585/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.