From: Jeff King Date: Sun, 26 Oct 2025 15:18:36 GMT Subject: Re: [PATCH] match_pathname(): give fnmatch one char of prefix context Message-ID: <20251026151836.GA2095501@coredump.intra.peff.net> In-Reply-To: On Thu, Oct 23, 2025 at 01:28:11PM -0700, Junio C Hamano wrote: > > I wonder how much this prefix-matching buys us in practice. There are > > two cases that are helped: > > > > 1. When there is no wildcard in the pattern at all, we skip fnmatch > > entirely. > > > > 2. We do a raw match of the prefix chars, shrinking the size of what > > is passed to fnmatch. > > > > My suspicion is that most of the improvement comes from (1), and it > > would be very easy to retain that case and get rid of (2). But I haven't > > done any measuring. > > The above matches my intuition as well. I wanted some actual numbers, so here's more than anybody probably cares to read on the subject. This is the test script I came up with: -- >8 -- #!/bin/sh pattern=$1; shift path=$1; shift versions= for i in "$@"; do versions="${versions:+$versions,}$i" done rm -rf repo git init repo cd repo echo "/$pattern" >.gitignore for i in $(seq 1 1000000); do eval "echo \"$path\"" done >input hyperfine -L git "$versions" -n "{git}" '../{git} check-ignore -q --no-index --stdin