• Bruce Dawson's avatar
    Make CheckLicense ~60x faster · 07bfa0dd
    Bruce Dawson authored
    After optimizing CheckForIncludeGuards the CheckLicense presubmit was
    the second slowest presubmit, taking about 35 minutes when run as part
    of "git cl presubmit --all". The cause of its slowness was initially
    non-obvious because it runs quite quickly on most files, however
    analysis showed that it could take 50+ seconds on some files. The files
    that it is slow on are those that lack a good license header, meaning
    that the regex match has to painstakingly scan the entire file.
    
    The optimization in this change is to recognize that there is a simple
    non-regex line that appears in all valid license headers, regardless of
    variants. If that line is absent then there is, necessarily, no valid
    license header, and searching for a line of text is something that
    Python can do extremely quickly.
    
    This change drops the CheckLicense time from about 35 minutes to about
    32 seconds.
    
    Trivia: _CommonChecks in third_party/blink/PRESUBMIT.py passes .* as the
    license, so I added an early-out for that to avoid pointlessly scanning
    those files.
    
    Bug: 1309977
    Change-Id: Ic2e56079675c2c5a2643d20dd492b1cc52e4ead2
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3584882Reviewed-by: 's avatarErik Staab <estaab@chromium.org>
    Reviewed-by: 's avatarGavin Mak <gavinmak@google.com>
    Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
    07bfa0dd
presubmit_canned_checks.py 71.2 KB