scmutil: avoid quadratic membership testing (
issue5969)
tr.changes['revs'] is an xrange, which has an O(n) __contains__
implementation. The `rev not in newrevs` lookup a few lines below
will therefore be O(n^2) if all incoming changesets are public.
This issue isn't present on @ because
45e05d39d9ce introduced
a custom type implementing an xrange primitive with O(1) contains
and switched tr.changes['revs'] to be an instance of that type.
We work around the problem on the stable branch by casting the
xrange to a set. This is a bit hacky because it requires allocating
memory to hold each integer in the range. But we are already
holding the full set of pulled revision numbers in memory
multiple times (such as in `tr.changes['phases']`). So this is
a relatively minor problem.
This issue has been present since the phases reporting code was
introduced in the 4.7 cycle by
eb9835014d20.
This change should be reverted/ignored when stable is merged into
default.
On the mozilla-unified repository with 483492 changesets, `hg clone`
time improves substantially:
before: 1843.700s user; 29.810s sys
after: 461.170s user; 29.360s sys
copies: correctly skip directories that have already been considered
Previously, `if dsrc in invalid` would never be true, since we added
`dsrc +"/"` to invalid, not `dsrc` itself. Since it's much more common for
individual files (not whole directories) to be moved, it seemed cleaner to
delay appending the "/" until we know we have some directory moves to
actually consider.
I haven't benchmarked this, but I imagine this is a mild performance win.
Differential Revision: https://phab.mercurial-scm.org/D4284