This is an archive of the discontinued Mercurial Phabricator instance.

lazyancestors: reuse __iter__ implementation in __contains__
ClosedPublic

Authored by martinvonz on Sep 8 2018, 3:38 AM.

Details

Summary

There was a comment in the code that said "Trying to do both iter
and contains using the same visit heap and seen set is complex
enough that it slows down both. Keep them separate.". However, it
seems easy and efficient to make contains keep an iterator across
calls.

I couldn't measure any slowdown from hg bundle --all (which seem to
call lazyancestors.contains frequently).

1HG: --

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

martinvonz created this revision.Sep 8 2018, 3:38 AM
yuja added a subscriber: yuja.Sep 8 2018, 4:33 AM

+ self._containsseen = set()
+ self._containsiter = iter(self)

Perhaps iter() needs to be extracted to a free function to avoid
reference cycle.

In D4508#68864, @yuja wrote:

+ self._containsseen = set()
+ self._containsiter = iter(self)

Perhaps iter() needs to be extracted to a free function to avoid
reference cycle.

Good point. I'll send a patch before this one to extract a free function.

Why do we care about reference cycles again? Because some runtimes don't have GC?

martinvonz updated this revision to Diff 10852.Sep 10 2018, 3:06 AM
This revision was automatically updated to reflect the committed changes.
yuja added a comment.Sep 10 2018, 7:54 AM

Queued, thanks.