Skip to content

Conversation

@ptarjan
Copy link

@ptarjan ptarjan commented Dec 24, 2025

Replace git rev-list --quiet with git cat-file -e for checking if a revision exists. This changes the operation from O(commits) to O(1).

Benchmarks (repo with ~1M commits, 5 runs each):

  • git rev-list --quiet: 5159-5191ms
  • git cat-file -e: 2-4ms

Both commands have the same semantics: return success if the revision exists in the local repo, failure otherwise.

Replace git rev-list --quiet with git cat-file -e for checking if a
revision exists. This changes the operation from O(commits) to O(1).

Benchmarks from a large monorepo:
- git rev-list --quiet <sha>: 5150ms
- git cat-file -e <sha>: 4ms

Both commands have the same semantics: return success if the revision
exists in the local repo, failure otherwise.
@ptarjan ptarjan force-pushed the claude/fix-slow-rev-exists-mkZg6 branch from 6a3e48c to 66d1c07 Compare December 24, 2025 21:08
@asottile
Copy link
Member

sorry but I unfortunately can't accept ai submissions

@asottile asottile closed this Dec 24, 2025
@asottile
Copy link
Member

this piece of code also isn't performance critical -- are you solving an actual problem?

@ptarjan
Copy link
Author

ptarjan commented Dec 24, 2025

sorry but I unfortunately can't accept ai submissions

Would you prefer me to set the author to my account?

this piece of code also isn't performance critical -- are you solving an actual problem?

Absolutely. As per the summary, in our repo our users are seeing a large delay with our pre-push hooks. So much so that about 7% of users are skipping them entirely. I'm trying to reduce the performance footprint and this was one of the largest slowdowns.

@ptarjan
Copy link
Author

ptarjan commented Dec 24, 2025

I updated the commit metadata to my name and username.

@asottile
Copy link
Member

I updated the commit metadata to my name and username.

that's just being disingenuous then? you didn't author this

@ptarjan
Copy link
Author

ptarjan commented Dec 24, 2025

that's just being disingenuous then? you didn't author this

I'm not sure what you mean by "author"? I mean I didn't open vim to make the changes to the text file, but I did instruct my terminal to "change git rev-list --quiet to git cat-file -e".

But I'd prefer not to split hairs if possible. What would you like me to do now so that we can accomplish this performance improvement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants