Re: Index files autocompletion too slow in big repositories (w / suggestion for improvement)
- From
Carlos Pita <carlosjosepita@gmail.com>
- Date
- Apr 14, 2017, 22:08 UTC
- Message-ID
- <CAELgYhfwwLZXGN9yHZ04koDwGn3=KbuJOxhLM-+PCbumTmMunw@mail.gmail.com>
- In-Reply-To
- <CAELgYhf1s43p62t6W14S=nDt-O247cPqsPMUDfye1OTnDND3Gg@mail.gmail.com>
This is much faster (below 0.1s):
__git_index_files ()
{
local dir="$(__gitdir)" root="${2-.}" file;
if [ -d "$dir" ]; then
__git_ls_files_helper "$root" "$1" | \
sed -r 's@/.*@@' | uniq | sort | uniq
fi
}time __git_index_files
real 0m0.075s user 0m0.083s sys 0m0.010s
Most of the improvement is due to the simpler, non-grouping, regex. Since I expect most of the common prefixes to arrive consecutively, running uniq before sort also improves things a bit. I'm not removing leading double quotes anymore (this isn't being done by the current version, anyway) but this doesn't seem to hurt.
Despite the dependence on sed this is ten times faster than the original, maybe an option to enable fast index completion or something like that might be desirable.
Best regards -- Carlos