comparison mercurial/revlogutils/deltas.py @ 39496:2f9f7889549b

snapshot: introduce an intermediate `_refinedgroups` generator This method will be used to improve the search for a good snapshot base. To keep things simpler, we introduce the necessary function before doing any delta base logic change. The next handful of commits will focus on refactoring the code to let that new logic land as clearly as possible. # General Idea Right now, the search for a good delta base stop whenever we found a good one. However, when using sparse-revlog, we should probably try a bit harder. We do significant effort to increase delta re-use by jumping on "unrelated" delta chains that provide better results. Moving to another chain for a better result is good, but we have no guarantee we jump at a reasonable point in that new chain. When we consider over the chains related to the parents, we start from the higher-level snapshots. This is a way to consider the snapshot closer to the current revision that has the best chance to produce a small delta. We do benefit from this walk order when jumping to a better "unrelated" stack. To counter-balance this, we'll introduce a way to "refine" the result. After a good delta have been found, we'll keep searching for a better delta, using the current best one as a starting point. # Target Setup The `finddeltainfo` method is responsible for the general search for a good delta. It requests candidates base from `_candidategroups` and decides which one are usable. The `_candidategroups` generator act as a top-level filter, it does not care about how we pick candidates, it just does basic filtering, excluding revisions that have been tested already or that are an obvious misfit. The `_rawgroups` generator is the one with the actual ancestors walking logic, It does not care about what would do a good delta and what was already tested, it just issues the initial candidates. We introduce a new `_refinedgroup` function to bridge the gap between `_candidategroups` and `_rawgroups`. It delegates the initial iteration logic and then performing relevant refining of the valid base once found. (This logic is yet to be added to function) All these logics are fairly independent and easier to understand when standing alone, not mixed with each other. It also makes it easy to test and try different approaches for one of those four layers without affecting the other ones. # Technical details To communicate `finddeltainfo` choice of "current best delta base" to the `_refinegroup` logic, we plan to use python co-routine feature. The `_candidategroups` and `_refinegroup` generators will become co-routine. This will allow `_refinegroup` to detect when a good delta have been found and triggers various refining steps. For now, `_candidategroups` will just pass the value down the stack. After poking at various option, the co-routine appears the best to keep each layers focus on its duty, without the need to spread implementation details across layers.
author Boris Feld <boris.feld@octobus.net>
date Fri, 07 Sep 2018 11:17:32 -0400
parents 6a53842727c1
children 5b308a4e6d03
comparison
equal deleted inserted replaced
39495:6a53842727c1 39496:2f9f7889549b
583 deltaparent = revlog.deltaparent 583 deltaparent = revlog.deltaparent
584 584
585 deltas_limit = textlen * LIMIT_DELTA2TEXT 585 deltas_limit = textlen * LIMIT_DELTA2TEXT
586 586
587 tested = set([nullrev]) 587 tested = set([nullrev])
588 for temptative in _rawgroups(revlog, p1, p2, cachedelta): 588 for temptative in _refinedgroups(revlog, p1, p2, cachedelta):
589 group = [] 589 group = []
590 for rev in temptative: 590 for rev in temptative:
591 # skip over empty delta (no need to include them in a chain) 591 # skip over empty delta (no need to include them in a chain)
592 while not (rev == nullrev or rev in tested or deltalength(rev)): 592 while not (rev == nullrev or rev in tested or deltalength(rev)):
593 rev = deltaparent(rev) 593 rev = deltaparent(rev)
618 deltaparent = revlog.deltaparent 618 deltaparent = revlog.deltaparent
619 issnapshot = revlog.issnapshot 619 issnapshot = revlog.issnapshot
620 for rev in revlog.revs(start_rev): 620 for rev in revlog.revs(start_rev):
621 if issnapshot(rev): 621 if issnapshot(rev):
622 cache[deltaparent(rev)].append(rev) 622 cache[deltaparent(rev)].append(rev)
623
624 def _refinedgroups(revlog, p1, p2, cachedelta):
625 good = None
626 for candidates in _rawgroups(revlog, p1, p2, cachedelta):
627 good = yield candidates
628 if good is not None:
629 break
623 630
624 def _rawgroups(revlog, p1, p2, cachedelta): 631 def _rawgroups(revlog, p1, p2, cachedelta):
625 """Provides group of revision to be tested as delta base 632 """Provides group of revision to be tested as delta base
626 633
627 This lower level function focus on emitting delta theorically interresting 634 This lower level function focus on emitting delta theorically interresting