comparison tests/test-annotate.t @ 29861:2f6d5c60f6fc stable

annotate: pre-calculate the "needed" dictionary (issue5360) The "needed" dict is used as a reference counter to free items in the giant "hist" dict. However, currently it is not very accurate and can lead to dropping "hist" items unnecessarily, for example, with the following DAG, -3- / \ 0--1--2--4-- The current algorithm will visit and calculate rev 1 twice, undesired. And it tries to be smart by clearing rev 1's parents: "pcache[1] = []" at the time hist[1] being accessed (note: hist[1] needs to be used twice, by rev 2 and rev 3). It can result in incorrect results if p1 of rev 4 deletes chunks belonging to rev 0. However, simply removing "needed" is not okay, because it will consume 10x memory: # without any change % HGRCPATH= lrun ./hg annotate mercurial/commands.py -r d130a38 3>&2 [1] MEMORY 49074176 CPUTIME 9.213 REALTIME 9.270 # with "needed" removed MEMORY 637673472 CPUTIME 8.164 REALTIME 8.249 This patch moves "needed" (and "pcache") calculation to a separate DFS to address the issue. It improves perf and fixes issue5360 by correctly reusing hist, while maintaining low memory usage. Some additional attempt has been made to further reduce memory usage, like changing "pcache[f] = []" to "del pcache[f]". Therefore the result can be both faster and lower memory usage: # with this patch applied MEMORY 47575040 CPUTIME 7.870 REALTIME 7.926 [1]: lrun is a lightweight sandbox built on Linux cgroup and namespace. It's used to measure CPU and memory usage here. Source code is available at github.com/quark-zju/lrun.
author Jun Wu <quark@fb.com>
date Fri, 02 Sep 2016 15:20:59 +0100
parents 56b2bcea2529
children 8c0c75aa3ff4
comparison
equal deleted inserted replaced
29853:d3b2da20a9c5 29861:2f6d5c60f6fc
604 $ hg annotate a -r 3 604 $ hg annotate a -r 3
605 0: A 605 0: A
606 3: B 606 3: B
607 607
608 $ cd .. 608 $ cd ..
609
610 Issue5360: Deleted chunk in p1 of a merge changeset
611
612 $ hg init repo-5360
613 $ cd repo-5360
614 $ echo 1 > a
615 $ hg commit -A a -m 1
616 $ echo 2 >> a
617 $ hg commit -m 2
618 $ echo a > a
619 $ hg commit -m a
620 $ hg update '.^' -q
621 $ echo 3 >> a
622 $ hg commit -m 3 -q
623 $ hg merge 2 -q
624 $ cat > a << EOF
625 > b
626 > 1
627 > 2
628 > 3
629 > a
630 > EOF
631 $ hg resolve --mark -q
632 $ hg commit -m m
633 $ hg annotate a
634 4: b
635 0: 1
636 1: 2
637 3: 3
638 2: a
639
640 $ cd ..