]> granicus.if.org Git - git/commit
sparse-checkout: use hashmaps for cone patterns
authorDerrick Stolee <dstolee@microsoft.com>
Mon, 21 Oct 2019 13:56:18 +0000 (13:56 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Oct 2019 03:42:05 +0000 (12:42 +0900)
commitfa1e8e3adb2be735d9d032f82fbc84a3d445730d
treecd59c4328fc4f822eb10e6a8f40c3c095b194832
parent95a6be78f301b14c6baa8e27922138a959ffafe1
sparse-checkout: use hashmaps for cone patterns

The parent and recursive patterns allowed by the "cone mode"
option in sparse-checkout are restrictive enough that we
can avoid using the regex parsing. Everything is based on
prefix matches, so we can use hashsets to store the prefixes
from the sparse-checkout file. When checking a path, we can
strip path entries from the path and check the hashset for
an exact match.

As a test, I created a cone-mode sparse-checkout file for the
Linux repository that actually includes every file. This was
constructed by taking every folder in the Linux repo and creating
the pattern pairs here:

/$folder/
!/$folder/*/

This resulted in a sparse-checkout file sith 8,296 patterns.
Running 'git read-tree -mu HEAD' on this file had the following
performance:

    core.sparseCheckout=false: 0.21 s (0.00 s)
     core.sparseCheckout=true: 3.75 s (3.50 s)
 core.sparseCheckoutCone=true: 0.23 s (0.01 s)

The times in parentheses above correspond to the time spent
in the first clear_ce_flags() call, according to the trace2
performance traces.

While this example is contrived, it demonstrates how these
patterns can slow the sparse-checkout feature.

Helped-by: Eric Wong <e@80x24.org>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c
dir.h
t/t1091-sparse-checkout-builtin.sh
unpack-trees.c