René's URL Explorer Experiment


Title: perf(diff): let the patch header regex skip to `diff --git` lines by g4lb · Pull Request #2349 · gitpython-developers/GitPython · GitHub

Open Graph Title: perf(diff): let the patch header regex skip to `diff --git` lines by g4lb · Pull Request #2349 · gitpython-developers/GitPython

X Title: perf(diff): let the patch header regex skip to `diff --git` lines by g4lb · Pull Request #2349 · gitpython-developers/GitPython

Description: Diff.re_header started with ^, so the regex engine tried the full header pattern at each byte of a patch. Now the pattern starts with the literal diff --git, and a lookbehind checks the line start. The engine tries the pattern only where diff --git occurs. The matches do not change. The Git commands do not change, and the Gix backend does not use this code. Benchmark (CPython 3.12) Before After Change diff(NULL_TREE, create_patch=True), 10,001 new files (7.7 MB) 166.5 ms 151.4 ms -9.1% diff(create_patch=True), GitPython 3.1.40 to main (343 files, 3.1 MB) 107.8 ms 99.9 ms -7.3% diff(create_patch=True), one commit (61 files, 78 KB) 18.9 ms 18.7 ms -1.3% (p = 0.29) Diff._index_from_patch_format(), a patch that adds a file of diff --git lines 521 µs 179 µs -65.6% I measured no slowdown on empty, one-line, CRLF, mode-only and binary patches (largest change +0.5%, p > 0.05). I used 15 interleaved rounds (30 for the small patches) and a Mann-Whitney test (Apple M5, CPython 3.8, 3.12 and 3.15). Import time of import git did not change (30 rounds). I did not measure other architectures or PyPy. Checks: pytest -m 'not net' passes on the CLI backend, and test/test_diff.py passes on the Gix backend. ruff check, ruff format --check and mypy pass. Old and new outputs matched on 1,023,000 random, malformed and real inputs. A new test makes sure that diff --git in hunk lines does not start a new file. The output does not change, so no test can fail without this change. Motivation: Faster diff(create_patch=True) for tools that read history patch by patch. An AI agent prepared this change, its measurements and this description.

Open Graph Description: Diff.re_header started with ^, so the regex engine tried the full header pattern at each byte of a patch. Now the pattern starts with the literal diff --git, and a lookbehind checks the line start....

X Description: Diff.re_header started with ^, so the regex engine tried the full header pattern at each byte of a patch. Now the pattern starts with the literal diff --git, and a lookbehind checks the line start....

Opengraph URL: https://github.com/gitpython-developers/GitPython/pull/2349

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:5bcf0bd2-3033-0673-fa61-b0266286055d
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id92F6:16A125:67D212:8AE607:6B00AB0A
html-safe-nonce73f70d61fec222f404bee558aab9a187710ef782e0df885a5d14ba68882600cc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MkY2OjE2QTEyNTo2N0QyMTI6OEFFNjA3OjZCMDBBQjBBIiwidmlzaXRvcl9pZCI6IjMyMTc2NTM5NjM2NzU0NDYwMjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac0b27bf9aca1b2de549da0affb0067b28f64c98906158b1d0625433a74d996443
hovercard-subject-tagpull_request:5392688554
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/gitpython-developers/GitPython/pull/2349/files
twitter:imagehttps://avatars.githubusercontent.com/u/16121666?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/16121666?s=400&v=4
og:image:altDiff.re_header started with ^, so the regex engine tried the full header pattern at each byte of a patch. Now the pattern starts with the literal diff --git, and a lookbehind checks the line start....
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None455b493e3402a3a3a06beac5d20bb7db3da060808b220aa48d6a7eca7c59863a
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git
octolytics-dimension-user_id503709
octolytics-dimension-user_logingitpython-developers
octolytics-dimension-repository_id1126087
octolytics-dimension-repository_nwogitpython-developers/GitPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1126087
octolytics-dimension-repository_network_root_nwogitpython-developers/GitPython
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
release2f575159976167242d488c0b062eb355c4e198b7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/gitpython-developers/GitPython/pull/2349/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fpull%2F2349%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%2Fgitpython-developers%2FGitPython%2Fpull%2F2349%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=gitpython-developers%2FGitPython
Reloadhttps://github.com/gitpython-developers/GitPython/pull/2349/files
Reloadhttps://github.com/gitpython-developers/GitPython/pull/2349/files
Reloadhttps://github.com/gitpython-developers/GitPython/pull/2349/files
gitpython-developershttps://github.com/gitpython-developers
GitPythonhttps://github.com/gitpython-developers/GitPython
Codehttps://github.com/gitpython-developers/GitPython
Issues1 (1)https://github.com/gitpython-developers/GitPython/issues
Pull requestshttps://github.com/gitpython-developers/GitPython/pulls
Discussionshttps://github.com/gitpython-developers/GitPython/discussions
Actionshttps://github.com/gitpython-developers/GitPython/actions
Security and quality42 (42)https://github.com/gitpython-developers/GitPython/security
Insightshttps://github.com/gitpython-developers/GitPython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fgitpython-developers%2FGitPython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fgitpython-developers%2FGitPython%2Fissues%2Fnew%2Fchoose
Byronhttps://github.com/Byron
gitpython-developers:mainhttps://github.com/gitpython-developers/GitPython/tree/main
g4lb:perf-diff-header-literalhttps://github.com/g4lb/GitPython/tree/perf-diff-header-literal
Conversation 0 https://github.com/gitpython-developers/GitPython/pull/2349
Commits 1 https://github.com/gitpython-developers/GitPython/pull/2349/commits
Checks 64 https://github.com/gitpython-developers/GitPython/pull/2349/checks
Files changed https://github.com/gitpython-developers/GitPython/pull/2349/files
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/2349/files
perf(diff): let the patch header regex skip to diff --git lines https://github.com/gitpython-developers/GitPython/pull/2349/files#top
Show all changes 1 commit https://github.com/gitpython-developers/GitPython/pull/2349/files
6bf2cca perf(diff): let the patch header regex skip to `diff --git` lines g4lb Nov 19, 2026 https://github.com/gitpython-developers/GitPython/pull/2349/commits/6bf2cca49d5aaa8cd71472e8daf0fc5ee67b7b0a
Clear filters https://github.com/gitpython-developers/GitPython/pull/2349/files
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/2349/files
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/2349/files
diff.py https://github.com/gitpython-developers/GitPython/pull/2349/files#diff-300633890a1b325dfed86bb5120d89465f0687f4f6b8d5701c44c02f0eee723a
test_diff.py https://github.com/gitpython-developers/GitPython/pull/2349/files#diff-a4c794e0849bb401148549f5efcaa756477ae6f7c2976d2ebf7cb56ff7850139
git/diff.pyhttps://github.com/gitpython-developers/GitPython/pull/2349/files#diff-300633890a1b325dfed86bb5120d89465f0687f4f6b8d5701c44c02f0eee723a
View file https://github.com/g4lb/GitPython/blob/6bf2cca49d5aaa8cd71472e8daf0fc5ee67b7b0a/git/diff.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/gitpython-developers/GitPython/pull/2349/{{ revealButtonHref }}
https://github.com/gitpython-developers/GitPython/pull/2349/files#diff-300633890a1b325dfed86bb5120d89465f0687f4f6b8d5701c44c02f0eee723a
https://github.com/gitpython-developers/GitPython/pull/2349/files#diff-300633890a1b325dfed86bb5120d89465f0687f4f6b8d5701c44c02f0eee723a
test/test_diff.pyhttps://github.com/gitpython-developers/GitPython/pull/2349/files#diff-a4c794e0849bb401148549f5efcaa756477ae6f7c2976d2ebf7cb56ff7850139
View file https://github.com/g4lb/GitPython/blob/6bf2cca49d5aaa8cd71472e8daf0fc5ee67b7b0a/test/test_diff.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/gitpython-developers/GitPython/pull/2349/{{ revealButtonHref }}
https://github.com/gitpython-developers/GitPython/pull/2349/files#diff-a4c794e0849bb401148549f5efcaa756477ae6f7c2976d2ebf7cb56ff7850139
https://github.com/gitpython-developers/GitPython/pull/2349/files#diff-a4c794e0849bb401148549f5efcaa756477ae6f7c2976d2ebf7cb56ff7850139
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/2349/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.