René's URL Explorer Experiment


Title: Pre-commit performance issues in our large repository · Issue #3603 · pre-commit/pre-commit · GitHub

Open Graph Title: Pre-commit performance issues in our large repository · Issue #3603 · pre-commit/pre-commit

X Title: Pre-commit performance issues in our large repository · Issue #3603 · pre-commit/pre-commit

Description: search you tried in the issue tracker is:issue state:open rev-list describe your issue Summary We are experiencing two significant performance bottlenecks: _rev_exists() (pre-push): Uses git rev-list --quiet which walks the entire commit...

Open Graph Description: search you tried in the issue tracker is:issue state:open rev-list describe your issue Summary We are experiencing two significant performance bottlenecks: _rev_exists() (pre-push): Uses git rev-li...

X Description: search you tried in the issue tracker is:issue state:open rev-list describe your issue Summary We are experiencing two significant performance bottlenecks: _rev_exists() (pre-push): Uses git rev-li...

Opengraph URL: https://github.com/pre-commit/pre-commit/issues/3603

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.3


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Pre-commit performance issues in our large repository","articleBody":"### search you tried in the issue tracker\n\nis:issue state:open rev-list\n\n### describe your issue\n\n## Summary\n\nWe are experiencing two significant performance bottlenecks:\n\n1. **`_rev_exists()`** (pre-push): Uses `git rev-list --quiet` which walks the entire commit history (~5.2s)\n2. **`_get_diff()`** (pre-commit): Scans the entire working tree after each hook (~250ms × N hooks)\n\n---\n\n## Issue 1: `_rev_exists()` in hook_impl.py (PRE-PUSH)\n\n### Problem\n\n```python\ndef _rev_exists(rev: str) -> bool:\n    return not subprocess.call(('git', 'rev-list', '--quiet', rev))\n```\n\n`git rev-list --quiet` walks the entire commit history to verify a revision exists.\n\n### Profiling\n\n| Command | Time | Notes |\n|---------|------|-------|\n| `git rev-list --quiet HEAD` | **5,201ms** | Current - walks ~1M commits |\n| `git rev-parse --verify --quiet HEAD` | **2.6ms** | Fix - just validates ref |\n\n**Speedup: 2000x**\n\n### Verified Fix\n\n```python\ndef _rev_exists(rev: str) -> bool:\n    return not subprocess.call(\n        ('git', 'rev-parse', '--verify', '--quiet', rev),\n        stdout=subprocess.DEVNULL,\n        stderr=subprocess.DEVNULL,\n    )\n```\n\n**Safety verification:**\n- Z40 (null SHA) case is already guarded: `remote_sha != Z40 and _rev_exists(remote_sha)`\n- Exit codes: both return 0 for valid refs, non-zero for invalid\n- Tested with: valid refs, invalid refs, commit SHAs\n\n---\n\n## Issue 2: `_get_diff()` in run.py (PRE-COMMIT)\n\n### Problem\n\n```python\ndef _get_diff() -> bytes:\n    _, out, _ = cmd_output_b(\n        'git', 'diff', '--no-ext-diff', '--no-textconv', '--ignore-submodules',\n        check=False,\n    )\n    return out\n```\n\nCalled after **every hook that runs** to detect if files were modified. Scans entire working tree.\n\n### Profiling\n\n| Scope | Time | Speedup |\n|-------|------|---------|\n| Full working tree | 250ms | 1x |\n| Scoped to hook files | 16ms | **15x** |\n\nWith 50 hooks running: 50 calls × 250ms = **12.5s seconds overhead**\n\n### Verified Fix\n\nScope diff to the files the hook processed:\n\n```python\ndef _get_diff(files: tuple[str, ...] = ()) -> bytes:\n    cmd = ['git', 'diff', '--no-ext-diff', '--no-textconv', '--ignore-submodules']\n    if files:\n        cmd.extend(['--', *files])\n    _, out, _ = cmd_output_b(*cmd, check=False)\n    return out\n```\n\n**Important caveat:** Only safe when `pass_filenames: true` (the default).\n\nFor hooks with `pass_filenames: false`, must fall back to full tree diff since they may modify files outside their trigger patterns (e.g., code generators).\n\nIn `_run_single_hook()`:\n```python\n# filenames from classifier are available before pass_filenames check\nfilenames = tuple(classifier.filenames_for_hook(hook))\n...\nif not hook.pass_filenames:\n    # Can't scope diff - hook may modify any file\n    diff_after = _get_diff()\nelse:\n    # Safe to scope diff to the files hook received\n    diff_after = _get_diff(filenames)\n```\n---\n\n## Other Slow Operations (No Easy Fix)\n\nThese scan the working tree and can't be easily optimized:\n\n| Operation | Time | Location | Notes |\n|-----------|------|----------|-------|\n| `intent_to_add_files()` | 257ms | git.py | Full tree scan required |\n| `_unstaged_changes_cleared()` | 265ms | staged_files_only.py | Full tree scan required |\n\nCould benefit from git's fsmonitor?\n\n---\n\n## Reproduction\n\n```bash\n# Test _rev_exists performance\npython3 -c \"\nimport time, subprocess\nfor cmd, name in [\n    (['git', 'rev-list', '--quiet', 'HEAD'], 'current'),\n    (['git', 'rev-parse', '--verify', '--quiet', 'HEAD'], 'fix'),\n]:\n    start = time.perf_counter()\n    subprocess.call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n    print(f'{name}: {(time.perf_counter()-start)*1000:.1f}ms')\n\"\n\n# Test _get_diff performance\npython3 -c \"\nimport time, subprocess\nfor scope in ['', '-- path/to/file.py']:\n    cmd = ['git', 'diff', '--no-ext-diff', '--no-textconv', '--ignore-submodules'] + scope.split()\n    start = time.perf_counter()\n    subprocess.run(cmd, capture_output=True)\n    print(f'{scope or 'full tree'}: {(time.perf_counter()-start)*1000:.1f}ms')\n\"\n```\n\n\n### pre-commit --version\n\n4.5.0\n\n### .pre-commit-config.yaml\n\n```yaml\n(sadly I can't share)\n```\n\n### ~/.cache/pre-commit/pre-commit.log (if present)\n\n_No response_","author":{"url":"https://github.com/ptarjan","@type":"Person","name":"ptarjan"},"datePublished":"2025-12-26T21:26:52Z","url":"https://github.com/pre-commit/pre-commit/issues/3603"}

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:577575d7-186d-7653-4dae-2310a3502c88
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9DB4:15F7F4:15ED1C4:1CEFBC4:6B066908
html-safe-nonced7de05ccc057c1315abed1d62d8b2925d089a5e9be4a113b2276cc55c856af59
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5REI0OjE1RjdGNDoxNUVEMUM0OjFDRUZCQzQ6NkIwNjY5MDgiLCJ2aXNpdG9yX2lkIjoiNjcyNzg3NTUxNDMwMjA5NzY3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb24b384ea439fd893f1c982c32827d3716505d86b21b47cf9fb88e95bd2bf288
hovercard-subject-tagissue:3764029052
github-keyboard-shortcutsrepository,issues,commits,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/pre-commit/pre-commit/3603/issue_layout
twitter:imagehttps://opengraph.githubassets.com/5f8362f96688f38cc87a64edb3ca2a06a4dc474f953dbaa2ab599c4e82bf6798/pre-commit/pre-commit/issues/3603
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/5f8362f96688f38cc87a64edb3ca2a06a4dc474f953dbaa2ab599c4e82bf6798/pre-commit/pre-commit/issues/3603
og:image:altsearch you tried in the issue tracker is:issue state:open rev-list describe your issue Summary We are experiencing two significant performance bottlenecks: _rev_exists() (pre-push): Uses git rev-li...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameptarjan
hostnamegithub.com
expected-hostnamegithub.com
None6324e6ac990fb6befbec840cc0e102a1071c339bfe8f9826bb12de2e3ba1d297
turbo-cache-controlno-preview
go-importgithub.com/pre-commit/pre-commit git https://github.com/pre-commit/pre-commit.git
octolytics-dimension-user_id6943086
octolytics-dimension-user_loginpre-commit
octolytics-dimension-repository_id17689377
octolytics-dimension-repository_nwopre-commit/pre-commit
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id17689377
octolytics-dimension-repository_network_root_nwopre-commit/pre-commit
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
release7f0aa75f4141d440c6110dc31af7ea7797abb6c4
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/pre-commit/pre-commit/issues/3603#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpre-commit%2Fpre-commit%2Fissues%2F3603
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%2Fpre-commit%2Fpre-commit%2Fissues%2F3603
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=pre-commit%2Fpre-commit
Reloadhttps://github.com/pre-commit/pre-commit/issues/3603
Reloadhttps://github.com/pre-commit/pre-commit/issues/3603
Reloadhttps://github.com/pre-commit/pre-commit/issues/3603
pre-commithttps://github.com/pre-commit
pre-commithttps://github.com/pre-commit/pre-commit
Codehttps://github.com/pre-commit/pre-commit
Issues17 (17)https://github.com/pre-commit/pre-commit/issues
Pull requests8 (8)https://github.com/pre-commit/pre-commit/pulls
Actionshttps://github.com/pre-commit/pre-commit/actions
Security and qualityhttps://github.com/pre-commit/pre-commit/security
Insightshttps://github.com/pre-commit/pre-commit/insights
https://github.com/pre-commit/pre-commit
New issuehttps://github.com/login?return_to=https://github.com/pre-commit/pre-commit/issues/3603
New issuehttps://github.com/login?return_to=https://github.com/pre-commit/pre-commit/issues/3603
Pre-commit performance issues in our large repositoryhttps://github.com/pre-commit/pre-commit/issues/3603#top
https://github.com/ptarjan
ptarjanhttps://github.com/ptarjan
on Dec 26, 2025https://github.com/pre-commit/pre-commit/issues/3603#issue-3764029052
ptarjanhttps://github.com/ptarjan
on Dec 26, 2025https://github.com/pre-commit/pre-commit/issues/3603#event-21762109851
https://github.com/asottile
asottilehttps://github.com/asottile
on Dec 26, 2025https://github.com/pre-commit/pre-commit/issues/3603#issuecomment-3693390051
asottilehttps://github.com/asottile
completedhttps://github.com/pre-commit/pre-commit/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Dec 26, 2025https://github.com/pre-commit/pre-commit/issues/3603#event-21762141498
https://github.com/asottile
asottilehttps://github.com/asottile
on Dec 26, 2025https://github.com/pre-commit/pre-commit/issues/3603#issuecomment-3693390379
pre-commithttps://github.com/pre-commit
on Dec 26, 2025https://github.com/pre-commit/pre-commit/issues/3603#event-21762143531
Sign up for freehttps://github.com/signup?return_to=https://github.com/pre-commit/pre-commit/issues/3603
Sign in to commenthttps://github.com/login?return_to=https://github.com/pre-commit/pre-commit/issues/3603
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

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.