This is an archive of the discontinued Mercurial Phabricator instance.

setdiscovery: precompute children revisions to avoid quadratic lookup
ClosedPublic

Authored by indygreg on Aug 17 2018, 5:31 PM.

Details

Summary

Moving away from dagutil a few commits ago introduced quadratic
behavior when resolving children revisions during discovery.

This commit introduces a precompute step of the children revisions
to avoid the bad behavior.

I believe the new code should have near identical performance to
what dagutil was doing before. Behavior is still slightly different
because we take into account filtered revisions. But this change was
made when we moved off dagutil.

I added a comment about multiple invocations of this function
redundantly calculating the children revisions. I believe this
potentially undesirable behavior was present when we used dagutil,
as the call to inverse() previously in this function created a new
object and required computing children on every invocation. I thought
we should document the potential for a performance issue rather than
let it go undocumented.

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

indygreg created this revision.Aug 17 2018, 5:31 PM
yuja added a subscriber: yuja.Aug 18 2018, 4:05 AM

+ parentrevs = repo.changelog.parentrevs
+ for rev in repo.changelog.revs(start=min(revsroots)):
+ # Always ensure revision has an entry so we don't need to worry about
+ # missing keys.
+ children.setdefault(rev, [])
+
+ for prev in parentrevs(rev):
+ if prev == nullrev:
+ continue
+
+ children.setdefault(prev, []).append(rev)

Just FYI, I remember I wrote a similar code, which is a53bfc2845f2.

This revision was automatically updated to reflect the committed changes.