Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stat diff summary performance #982

Merged
merged 1 commit into from
Mar 17, 2024

Conversation

lnewson
Copy link
Contributor

@lnewson lnewson commented Mar 14, 2024

While investigating why running git log was taking so long for a repo (it's pretty large and there was some mass renaming). There was one commit (~4000 changed files) that was taking ~19s to parse the diff summary for and overall it would take ~40s. When running the equivalent native git command it only took ~8s.

Looking into it a bit more, I believe the main cause was that the regex is doing a lot of backtracking, especially for long filenames. So my fix was to just add ^ to make it match from the start of the line and avoid some backtracking.

Before:

> run = async () => {
  const start = performance.now();
  await simpleGit().log({ '--stat': 4906 });
  console.log('Time', performance.now() - start);
}
> await run()
Time 40318.625875

After:

> run = async () => {
  const start = performance.now();
  await simpleGit().log({ '--stat': 4906 });
  console.log('Time', performance.now() - start);
}
> await run()
Time 9392.257582999999

Copy link

changeset-bot bot commented Mar 14, 2024

🦋 Changeset detected

Latest commit: 8a3118d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
simple-git Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@steveukx steveukx merged commit 175ae77 into steveukx:main Mar 17, 2024
5 checks passed
@steveukx
Copy link
Owner

Thank you for the detailed description and the pull request. I've now released a new version that includes this change.

@lnewson lnewson deleted the lnewson-diff-perf branch March 17, 2024 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants