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
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,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-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:1eca2e26-5d8c-0f4d-1b9b-5108126ebaf2 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A306:1087D4:2109E87:2C227FD:6B018A6D |
| html-safe-nonce | fbedab4f60f50772d3a510d5a837fac1f6f893a8e0e17c9474b63aead18fd1b6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzA2OjEwODdENDoyMTA5RTg3OjJDMjI3RkQ6NkIwMThBNkQiLCJ2aXNpdG9yX2lkIjoiNDU0ODQ3OTQzMDM2MzgxMDQxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3c374d5476a9543f15b689be94f7daea6475d691da0fc29c269af073bdf639dc |
| hovercard-subject-tag | pull_request:5392688554 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/gitpython-developers/GitPython/pull/2349/files |
| twitter:image | https://avatars.githubusercontent.com/u/16121666?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/16121666?s=400&v=4 |
| og:image:alt | 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.... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width