This is an archive of the discontinued Mercurial Phabricator instance.

match: improve includematcher.visitchildrenset to be much faster and cached

Authored by spectral on Aug 21 2018, 6:18 PM.



This improves the speed of visitchildrenset considerably, especially when there
are complicated matchers involved that may have many entries in _dirs or

Unfortunately the benchmark isn't easily upstreamed due to its reliance on (primarily due to the conflict when importing
it if I were to contribute the benchmark as contrib/
instead of asv or some other perf measurement system.

To describe the benchmark briefly: I generated an includematcher of either 5 or
3500 "rootfilesin:prefix1/prefix2/prefix3/<randomsubdirs, 1-8 levels deep>"
items in the 'setup' function, and then called
im.visitchildrenset('prefix1/prefix2') in the 'stmt' function in perf.timeit.

For the set of 5:

  • before: 15.3 us +- 2.9 us
  • after: 1.59 us +- 0.02 us

For the set of 3500:

  • before: 3.90 ms +- 0.10 ms
  • after: 3.15 us +- 0.09 us (note the m->u change)

Diff Detail

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

Event Timeline

spectral created this revision.Aug 21 2018, 6:18 PM
durin42 added inline comments.

could we extract this class to module-level and pass matcherself as a ctor parameter instead?

spectral updated this revision to Diff 10534.Aug 22 2018, 9:00 PM
spectral marked an inline comment as done.Aug 22 2018, 9:00 PM
yuja added a subscriber: yuja.Aug 29 2018, 6:55 PM

Can't apply. Can you rebase?

spectral updated this revision to Diff 10774.Sep 4 2018, 6:44 PM
In D4351#67751, @yuja wrote:

Can't apply. Can you rebase?

Done, sorry for the delay.

yuja added a comment.Sep 6 2018, 8:08 AM

Queued, thanks.

This revision was automatically updated to reflect the committed changes.