Bug 5868 - hg log --template "{bookmarks}" runs slowly in the presence of many revisions and bookmarks
Summary: hg log --template "{bookmarks}" runs slowly in the presence of many revisions...
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: templater (show other bugs)
Version: 4.4.2
Hardware: PC Linux
: wish bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-04 15:48 UTC by Mitchell Plamann
Modified: 2018-05-10 06:57 UTC (History)
2 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mitchell Plamann 2018-05-04 15:48 UTC
The command

  hg log --template "{bookmarks}"

runs very slowly on repositories with large numbers of bookmarks and revisions.

For each revision, the "{bookmarks}" template iterates over every bookmark, picking out the ones that match the revision, doing a total of O(number of revisions * number of bookmarks) work.

It seems like it should be possible to reduce this to O(number of revisions + number of bookmarks) by computing a mapping from revisions to bookmarks and reusing that for each revision.
Comment 1 HG Bot 2018-05-09 08:35 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/04ceb267271a
Yuya Nishihara <yuya@tcha.org>
bookmarks: cache reverse mapping (issue5868)

I chose a simpler implementation. If the initial cost of building reverse
mapping is significant, we'll have to move it under @propertycache.

The nodemap could be a dict of sets, but I think keeping a sorted list is
better since each node is likely to have zero/one bookmark.

Micro-benchmark with 1001 bookmarks and 1001 revisions:

  $ for n in `seq 0 1000`; do touch $n; hg book book$n; hg ci -qAm$n; done
  $ hg bookmarks --time > /dev/null
  (orig) time: real 0.040 secs (user 0.050+0.000 sys 0.000+0.000)
  (new)  time: real 0.040 secs (user 0.040+0.000 sys 0.010+0.000)
  $ hg log -T '{bookmarks}\n' --time > /dev/null
  (orig) time: real 0.160 secs (user 0.160+0.000 sys 0.000+0.000)
  (new)  time: real 0.090 secs (user 0.100+0.000 sys 0.000+0.000)

(please test the fix)
Comment 2 Mitchell Plamann 2018-05-09 12:53 UTC
I've tested revision 04ceb267271a, and it does resolve the problem. Thank you!