Commit 5f63d3c4 authored by Bruce Dawson's avatar Bruce Dawson Committed by LUCI CQ

Increase presubmit --all speed (no diffs) by 100x

presubmit --all tells the presubmit system that all files are 'modified'
but ChangedContents still goes off to see what changes are present. If
most files were unchanged this was all handled perfectly, but if _all_
files were unchanged then _GitDiffCache would interpret the empty
dictionary of changes as a reason to ask git for diffs, millions of
times. This made some checks take more than 100x as long. The overall
effect on presubmit --all time is not known because I was never willing
to wait the multiple days for them to terminate.

That is, this would take many days to run:
  git checkout -b empty -t origin/main
  git cl presubmit --all

whereas a single-character change to any file would let this run in
about two hours.

After three weeks of working on presubmits I only hit this twice which
is why it took me so long to realize what the problem was.

Bug: 1309977
Change-Id: Ib280ea386107843b9174d835b0895316a5ed240c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3589900Reviewed-by: 's avatarAravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
parent 7d2693ad
......@@ -898,7 +898,9 @@ class _GitDiffCache(_DiffCache):
self._diffs_by_file = None
def GetDiff(self, path, local_root):
if not self._diffs_by_file:
# Compare against None to distinguish between None and an initialized but
# empty dictionary.
if self._diffs_by_file == None:
# Compute a single diff for all files and parse the output; should
# with git this is much faster than computing one diff for each file.
diffs = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment