Skip to content

Use git diff --stat as possible optimization for changeset diff stats

Created by: mrnugget

To compute the diff stats for a campaign we currently:

  1. make N requests to gitserver (N = number of changesets in a campaing) to get the full diff for each changset
  2. parse each diff to get the diff stats
  3. add up the diff stats

What we could do as an optimization is to ask gitserver for the diff stat directly.


This call to DiffStat

https://github.com/sourcegraph/sourcegraph/blob/938f0628eba30c9f29cc6376880caf0d4c384d32/enterprise/internal/campaigns/resolvers/campaigns.go#L307-L314

ends up making the request to gitserver here:

https://github.com/sourcegraph/sourcegraph/blob/938f0628eba30c9f29cc6376880caf0d4c384d32/cmd/frontend/graphqlbackend/repository_comparison.go#L183-L222

We could, for example, have a method on fileDiffConnectionResolver, called ComputeDiffStatOnly, that makes nearly the same request to gitserver, except that it adds the --stat flag to the git diff command and parses that output.

Or we can use --numstat or --shortstat.