comparison mercurial/revlogutils/deltas.py @ 41109:3e1960e23e6b

delta: reuse _findsnapshot call from previous stage Two different stage of the sparse-revlog logic needs the _findsnapshot data. To avoid recomputing it twice, make it possible to reuse the first computation in the second step. example affected manifest write before: 0.067141s after: 0.064252s (-5%) (total gain since start of series: 95%)
author Boris Feld <boris.feld@octobus.net>
date Thu, 20 Dec 2018 10:16:24 +0100
parents 38e88450138c
children 189e06b2d719
comparison
equal deleted inserted replaced
41108:38e88450138c 41109:3e1960e23e6b
711 # build delta will reuse the cache 711 # build delta will reuse the cache
712 good = yield (cachedelta[0],) 712 good = yield (cachedelta[0],)
713 if good is not None: 713 if good is not None:
714 yield None 714 yield None
715 return 715 return
716 for candidates in _rawgroups(revlog, p1, p2, cachedelta): 716 snapshots = collections.defaultdict(list)
717 for candidates in _rawgroups(revlog, p1, p2, cachedelta, snapshots):
717 good = yield candidates 718 good = yield candidates
718 if good is not None: 719 if good is not None:
719 break 720 break
720 721
721 # If sparse revlog is enabled, we can try to refine the available deltas 722 # If sparse revlog is enabled, we can try to refine the available deltas
732 base = revlog.deltaparent(good) 733 base = revlog.deltaparent(good)
733 if base == nullrev: 734 if base == nullrev:
734 break 735 break
735 good = yield (base,) 736 good = yield (base,)
736 # refine snapshot up 737 # refine snapshot up
737 # 738 if not snapshots:
738 # XXX the _findsnapshots call can be expensive and is "duplicated" with 739 _findsnapshots(revlog, snapshots, good + 1)
739 # the one done in `_rawgroups`. Once we start working on performance,
740 # we should make the two logics share this computation.
741 snapshots = collections.defaultdict(list)
742 _findsnapshots(revlog, snapshots, good + 1)
743 previous = None 740 previous = None
744 while good != previous: 741 while good != previous:
745 previous = good 742 previous = good
746 children = tuple(sorted(c for c in snapshots[good])) 743 children = tuple(sorted(c for c in snapshots[good]))
747 good = yield children 744 good = yield children
748 745
749 # we have found nothing 746 # we have found nothing
750 yield None 747 yield None
751 748
752 def _rawgroups(revlog, p1, p2, cachedelta): 749 def _rawgroups(revlog, p1, p2, cachedelta, snapshots=None):
753 """Provides group of revision to be tested as delta base 750 """Provides group of revision to be tested as delta base
754 751
755 This lower level function focus on emitting delta theorically interresting 752 This lower level function focus on emitting delta theorically interresting
756 without looking it any practical details. 753 without looking it any practical details.
757 754
777 elif len(parents) > 0: 774 elif len(parents) > 0:
778 # Test all parents (1 or 2), and keep the best candidate 775 # Test all parents (1 or 2), and keep the best candidate
779 yield parents 776 yield parents
780 777
781 if sparse and parents: 778 if sparse and parents:
782 snapshots = collections.defaultdict(list) # map: base-rev: snapshot-rev 779 if snapshots is None:
780 # map: base-rev: snapshot-rev
781 snapshots = collections.defaultdict(list)
783 # See if we can use an existing snapshot in the parent chains to use as 782 # See if we can use an existing snapshot in the parent chains to use as
784 # a base for a new intermediate-snapshot 783 # a base for a new intermediate-snapshot
785 # 784 #
786 # search for snapshot in parents delta chain 785 # search for snapshot in parents delta chain
787 # map: snapshot-level: snapshot-rev 786 # map: snapshot-level: snapshot-rev