This is an archive of the discontinued Mercurial Phabricator instance.

match: convert O(n) to O(log n) in exactmatcher.visitchildrenset
ClosedPublic

Authored by spectral on Apr 1 2021, 3:21 PM.

Details

Summary

When using narrow, during rebase this is called (at least) once per directory in
the set of files in the commit being rebased. Every time it's called, we did the
set arithmetic (now extracted and cached), which was probably pretty cheap but
not necessary to repeat each time, looped over every item in the matcher and
kept things that started with the directory we were querying.

With very large narrowspecs, and a commit that touched a file in a large number
of directories, this was slow. In a pathological repo, the rebase of a single
commit (that touched over 17k files, I believe in approximately as many
directories) with a narrowspec that had >32k entries took 8,246s of profiled
time, with 5,007s of that spent in visitchildrenset (transitively). With this
change, the time spent in visitchildrenset is less than 34s (which is where my
profile cut off). Most of the remaining time was network access due to our
custom remotefilelog-based setup not properly prefetching.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

spectral created this revision.Apr 1 2021, 3:21 PM
Alphare accepted this revision.Apr 8 2021, 6:20 AM
Alphare added a subscriber: Alphare.

I'm hoping that (at least) some of that logic could become obsolete with the new dirstate rewrite since we'll have a tree structure. For now this looks reasonable thanks to your generous comments.

pulkit accepted this revision.Apr 8 2021, 12:50 PM
This revision is now accepted and ready to land.Apr 8 2021, 12:50 PM