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:1eca2e26-5d8c-0f4d-1b9b-5108126ebaf2
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA306:1087D4:2109E87:2C227FD:6B018A6D
html-safe-noncefbedab4f60f50772d3a510d5a837fac1f6f893a8e0e17c9474b63aead18fd1b6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzA2OjEwODdENDoyMTA5RTg3OjJDMjI3RkQ6NkIwMThBNkQiLCJ2aXNpdG9yX2lkIjoiNDU0ODQ3OTQzMDM2MzgxMDQxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac3c374d5476a9543f15b689be94f7daea6475d691da0fc29c269af073bdf639dc
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
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttp://github.com/gitpython-developers/GitPython/pull/2349/files#start-of-content
http://github.com/
Sign inhttp://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 inhttp://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fpull%2F2349%2Ffiles
Sign uphttp://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
Reloadhttp://github.com/gitpython-developers/GitPython/pull/2349/files
Reloadhttp://github.com/gitpython-developers/GitPython/pull/2349/files
Reloadhttp://github.com/gitpython-developers/GitPython/pull/2349/files
gitpython-developershttp://github.com/gitpython-developers
GitPythonhttp://github.com/gitpython-developers/GitPython
Codehttp://github.com/gitpython-developers/GitPython
Issues1 (1)http://github.com/gitpython-developers/GitPython/issues
Pull requestshttp://github.com/gitpython-developers/GitPython/pulls
Discussionshttp://github.com/gitpython-developers/GitPython/discussions
Actionshttp://github.com/gitpython-developers/GitPython/actions
Security and quality42 (42)http://github.com/gitpython-developers/GitPython/security
Insightshttp://github.com/gitpython-developers/GitPython/insights
Sign up for GitHub http://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 inhttp://github.com/login?return_to=%2Fgitpython-developers%2FGitPython%2Fissues%2Fnew%2Fchoose
Byronhttp://github.com/Byron
gitpython-developers:mainhttp://github.com/gitpython-developers/GitPython/tree/main
g4lb:perf-diff-header-literalhttp://github.com/g4lb/GitPython/tree/perf-diff-header-literal
Conversation 0 http://github.com/gitpython-developers/GitPython/pull/2349
Commits 1 http://github.com/gitpython-developers/GitPython/pull/2349/commits
Checks 64 http://github.com/gitpython-developers/GitPython/pull/2349/checks
Files changed 2 http://github.com/gitpython-developers/GitPython/pull/2349/files
perf(diff): let the patch header regex skip to diff --git lines http://github.com/gitpython-developers/GitPython/pull/2349/files#top
Show all changes 1 commit http://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 http://github.com/gitpython-developers/GitPython/pull/2349/commits/6bf2cca49d5aaa8cd71472e8daf0fc5ee67b7b0a
Clear filters http://github.com/gitpython-developers/GitPython/pull/2349/files
Please reload this pagehttp://github.com/gitpython-developers/GitPython/pull/2349/files
Please reload this pagehttp://github.com/gitpython-developers/GitPython/pull/2349/files
diff.py http://github.com/gitpython-developers/GitPython/pull/2349/files#diff-300633890a1b325dfed86bb5120d89465f0687f4f6b8d5701c44c02f0eee723a
test_diff.py http://github.com/gitpython-developers/GitPython/pull/2349/files#diff-a4c794e0849bb401148549f5efcaa756477ae6f7c2976d2ebf7cb56ff7850139
git/diff.pyhttp://github.com/gitpython-developers/GitPython/pull/2349/files#diff-300633890a1b325dfed86bb5120d89465f0687f4f6b8d5701c44c02f0eee723a
View file http://github.com/g4lb/GitPython/blob/6bf2cca49d5aaa8cd71472e8daf0fc5ee67b7b0a/git/diff.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
http://github.com/gitpython-developers/GitPython/pull/2349/{{ revealButtonHref }}
http://github.com/gitpython-developers/GitPython/pull/2349/files#diff-300633890a1b325dfed86bb5120d89465f0687f4f6b8d5701c44c02f0eee723a
http://github.com/gitpython-developers/GitPython/pull/2349/files#diff-300633890a1b325dfed86bb5120d89465f0687f4f6b8d5701c44c02f0eee723a
test/test_diff.pyhttp://github.com/gitpython-developers/GitPython/pull/2349/files#diff-a4c794e0849bb401148549f5efcaa756477ae6f7c2976d2ebf7cb56ff7850139
View file http://github.com/g4lb/GitPython/blob/6bf2cca49d5aaa8cd71472e8daf0fc5ee67b7b0a/test/test_diff.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
http://github.com/gitpython-developers/GitPython/pull/2349/{{ revealButtonHref }}
http://github.com/gitpython-developers/GitPython/pull/2349/files#diff-a4c794e0849bb401148549f5efcaa756477ae6f7c2976d2ebf7cb56ff7850139
http://github.com/gitpython-developers/GitPython/pull/2349/files#diff-a4c794e0849bb401148549f5efcaa756477ae6f7c2976d2ebf7cb56ff7850139
Please reload this pagehttp://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.