sparse-revlog: implement algorithm to write sparse delta chains (
issue5480)
The classic behavior of revlog._isgooddeltainfo is to consider the span size
of the whole delta chain, and limit it to 4 * textlen.
Once sparse-revlog writing is allowed (and enforced with a requirement),
revlog._isgooddeltainfo considers the span of the largest chunk as the
distance used in the verification, instead of using the span of the whole
delta chain.
In order to compute the span of the largest chunk, we need to slice into
chunks a chain with the new revision at the top of the revlog, and take the
maximal span of these chunks. The sparse read density is a parameter to the
slicing, as it will stop when the global read density reaches this threshold.
For instance, a density of 50% means that 2 of 4 read bytes are actually used
for the reconstruction of the revision (the others are part of other chains).
This allows a new revision to be potentially stored with a diff against
another revision anywhere in the history, instead of forcing it in the last 4
* textlen. The result is a much better compression on repositories that have
many concurrent branches. Here are a comparison between using deltas from
current upstream (aggressive-merge-deltas on by default) and deltas from a
sparse-revlog
Comparison of `.hg/store/` size:
mercurial (6.74% merges):
before: 46,831,873 bytes
after: 46,795,992 bytes (no relevant change)
pypy (8.30% merges):
before: 333,524,651 bytes
after: 308,417,511 bytes -8%
netbeans (34.21% merges):
before: 1,141,847,554 bytes
after: 1,131,093,161 bytes -1%
mozilla-central (4.84% merges):
before: 2,344,248,850 bytes
after: 2,328,459,258 bytes -1%
large-private-repo-A (merge 19.73%)
before: 41,510,550,163 bytes
after: 8,121,763,428 bytes -80%
large-private-repo-B (23.77%)
before: 58,702,221,709 bytes
after: 8,351,588,828 bytes -76%
Comparison of `00manifest.d` size:
mercurial (6.74% merges):
before: 6,143,044 bytes
after: 6,107,163 bytes
pypy (8.30% merges):
before: 52,941,780 bytes
after: 27,834,082 bytes -48%
netbeans (34.21% merges):
before: 130,088,982 bytes
after: 119,337,636 bytes -10%
mozilla-central (4.84% merges):
before: 215,096,339 bytes
after: 199,496,863 bytes -8%
large-private-repo-A (merge 19.73%)
before: 33,725,285,081 bytes
after: 390,302,545 bytes -99%
large-private-repo-B (23.77%)
before: 49,457,701,645 bytes
after: 1,366,752,187 bytes -97%
The better delta chains provide a performance boost in relevant repositories:
pypy, bundling 1000 revisions:
before: 1.670s
after: 1.149s -31%
Unbundling got a bit slower. probably because the sparse algorithm is still
pure
python.
pypy, unbundling 1000 revisions:
before: 4.062s
after: 4.507s +10%
Performance of bundle/unbundle in repository with few concurrent branches (eg:
mercurial) are unaffected.
No significant differences have been noticed then timing `hg push` and `hg
pull` locally. More state timings are being gathered.
Same as for aggressive-merge-delta, better delta comes with longer delta
chains. Longer chains have a performance impact. For example. The length of
the chain needed to get the manifest of pypy's tip moves from 82 item to 1929
items. This moves the restore time from 3.88ms to 11.3ms.
Delta chain length is an independent issue that affects repository without
this changes. It will be dealt with independently.
No significant differences have been observed on repositories where
`sparse-revlog` have not much effect (mercurial, unity, netbeans). On pypy,
small differences have been observed on some operation affected by delta chain
building and retrieval.
pypy, perfmanifest
before: 0.006162s
after: 0.017899s +190%
pypy, commit:
before: 0.382
after: 0.376 -1%
pypy, status:
before: 0.157
after: 0.168 +7%
More comprehensive and stable timing comparisons are in progress.
$ . "$TESTDIR/narrow-library.sh"
$ hg init master
$ cd master
$ cat >> .hg/hgrc <<EOF
> [narrow]
> serveellipses=True
> EOF
$ for x in `$TESTDIR/seq.py 10`
> do
> echo $x > "f$x"
> hg add "f$x"
> hg commit -m "Commit f$x"
> done
$ cd ..
narrow clone a couple files, f2 and f8
$ hg clone --narrow ssh://user@dummy/master narrow --include "f2" --include "f8"
requesting all changes
adding changesets
adding manifests
adding file changes
added 5 changesets with 2 changes to 2 files
new changesets *:* (glob)
updating to branch default
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd narrow
$ ls
f2
f8
$ cat f2 f8
2
8
$ cd ..
change every upstream file twice
$ cd master
$ for x in `$TESTDIR/seq.py 10`
> do
> echo "update#1 $x" >> "f$x"
> hg commit -m "Update#1 to f$x" "f$x"
> done
$ for x in `$TESTDIR/seq.py 10`
> do
> echo "update#2 $x" >> "f$x"
> hg commit -m "Update#2 to f$x" "f$x"
> done
$ cd ..
look for incoming changes
$ cd narrow
$ hg incoming --limit 3
comparing with ssh://user@dummy/master
searching for changes
changeset: 5:ddc055582556
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: Update#1 to f1
changeset: 6:f66eb5ad621d
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: Update#1 to f2
changeset: 7:c42ecff04e99
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: Update#1 to f3
Interrupting the pull is safe
$ hg --config hooks.pretxnchangegroup.bad=false pull -q
transaction abort!
rollback completed
abort: pretxnchangegroup.bad hook exited with status 1
[255]
$ hg id
223311e70a6f tip
pull new changes down to the narrow clone. Should get 8 new changesets: 4
relevant to the narrow spec, and 4 ellipsis nodes gluing them all together.
$ hg pull
pulling from ssh://user@dummy/master
searching for changes
adding changesets
adding manifests
adding file changes
added 9 changesets with 4 changes to 2 files
new changesets *:* (glob)
(run 'hg update' to get a working copy)
$ hg log -T '{rev}: {desc}\n'
13: Update#2 to f10
12: Update#2 to f8
11: Update#2 to f7
10: Update#2 to f2
9: Update#2 to f1
8: Update#1 to f8
7: Update#1 to f7
6: Update#1 to f2
5: Update#1 to f1
4: Commit f10
3: Commit f8
2: Commit f7
1: Commit f2
0: Commit f1
$ hg update tip
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
add a change and push it
$ echo "update#3 2" >> f2
$ hg commit -m "Update#3 to f2" f2
$ hg log f2 -T '{rev}: {desc}\n'
14: Update#3 to f2
10: Update#2 to f2
6: Update#1 to f2
1: Commit f2
$ hg push
pushing to ssh://user@dummy/master
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
$ cd ..
$ cd master
$ hg log f2 -T '{rev}: {desc}\n'
30: Update#3 to f2
21: Update#2 to f2
11: Update#1 to f2
1: Commit f2
$ hg log -l 3 -T '{rev}: {desc}\n'
30: Update#3 to f2
29: Update#2 to f10
28: Update#2 to f9
Can pull into repo with a single commit
$ cd ..
$ hg clone -q --narrow ssh://user@dummy/master narrow2 --include "f1" -r 0
$ cd narrow2
$ hg pull -q -r 1
transaction abort!
rollback completed
abort: pull failed on remote
[255]
Can use 'hg share':
$ cat >> $HGRCPATH <<EOF
> [extensions]
> share=
> EOF
$ cd ..
$ hg share narrow2 narrow2-share
updating working directory
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd narrow2-share
$ hg status
We should also be able to unshare without breaking everything:
$ hg unshare
devel-warn: write with no wlock: "narrowspec" at: */hgext/narrow/narrowrepo.py:* (unsharenarrowspec) (glob)
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
1 files, 1 changesets, 1 total revisions