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.
$ cat >> $HGRCPATH <<EOF
> [experimental]
> bundle-phases=yes
> [extensions]
> strip=
> drawdag=$TESTDIR/drawdag.py
> EOF
Set up repo with linear history
$ hg init linear
$ cd linear
$ hg debugdrawdag <<'EOF'
> E
> |
> D
> |
> C
> |
> B
> |
> A
> EOF
$ hg phase --public A
$ hg phase --force --secret D
$ hg log -G -T '{desc} {phase}\n'
o E secret
|
o D secret
|
o C draft
|
o B draft
|
o A public
Phases are restored when unbundling
$ hg bundle --base B -r E bundle
3 changesets found
$ hg debugbundle bundle
Stream params: {Compression: BZ}
changegroup -- {nbchanges: 3, targetphase: 2, version: 02} (mandatory: True)
26805aba1e600a82e93661149f2313866a221a7b
f585351a92f85104bff7c284233c338b10eb1df7
9bc730a19041f9ec7cb33c626e811aa233efb18c
cache:rev-branch-cache -- {} (mandatory: False)
phase-heads -- {} (mandatory: True)
26805aba1e600a82e93661149f2313866a221a7b draft
$ hg strip --no-backup C
$ hg unbundle -q bundle
$ rm bundle
$ hg log -G -T '{desc} {phase}\n'
o E secret
|
o D secret
|
o C draft
|
o B draft
|
o A public
Root revision's phase is preserved
$ hg bundle -a bundle
5 changesets found
$ hg strip --no-backup A
$ hg unbundle -q bundle
$ rm bundle
$ hg log -G -T '{desc} {phase}\n'
o E secret
|
o D secret
|
o C draft
|
o B draft
|
o A public
Completely public history can be restored
$ hg phase --public E
$ hg bundle -a bundle
5 changesets found
$ hg strip --no-backup A
$ hg unbundle -q bundle
$ rm bundle
$ hg log -G -T '{desc} {phase}\n'
o E public
|
o D public
|
o C public
|
o B public
|
o A public
Direct transition from public to secret can be restored
$ hg phase --secret --force D
$ hg bundle -a bundle
5 changesets found
$ hg strip --no-backup A
$ hg unbundle -q bundle
$ rm bundle
$ hg log -G -T '{desc} {phase}\n'
o E secret
|
o D secret
|
o C public
|
o B public
|
o A public
Revisions within bundle preserve their phase even if parent changes its phase
$ hg phase --draft --force B
$ hg bundle --base B -r E bundle
3 changesets found
$ hg strip --no-backup C
$ hg phase --public B
$ hg unbundle -q bundle
$ rm bundle
$ hg log -G -T '{desc} {phase}\n'
o E secret
|
o D secret
|
o C draft
|
o B public
|
o A public
Phase of ancestors of stripped node get advanced to accommodate child
$ hg bundle --base B -r E bundle
3 changesets found
$ hg strip --no-backup C
$ hg phase --force --secret B
$ hg unbundle -q bundle
$ rm bundle
$ hg log -G -T '{desc} {phase}\n'
o E secret
|
o D secret
|
o C draft
|
o B draft
|
o A public
Unbundling advances phases of changesets even if they were already in the repo.
To test that, create a bundle of everything in draft phase and then unbundle
to see that secret becomes draft, but public remains public.
$ hg phase --draft --force A
$ hg phase --draft E
$ hg bundle -a bundle
5 changesets found
$ hg phase --public A
$ hg phase --secret --force E
$ hg unbundle -q bundle
$ rm bundle
$ hg log -G -T '{desc} {phase}\n'
o E draft
|
o D draft
|
o C draft
|
o B draft
|
o A public
Unbundling change in the middle of a stack does not affect later changes
$ hg strip --no-backup E
$ hg phase --secret --force D
$ hg log -G -T '{desc} {phase}\n'
o D secret
|
o C draft
|
o B draft
|
o A public
$ hg bundle --base A -r B bundle
1 changesets found
$ hg unbundle -q bundle
$ rm bundle
$ hg log -G -T '{desc} {phase}\n'
o D secret
|
o C draft
|
o B draft
|
o A public
$ cd ..
Set up repo with non-linear history
$ hg init non-linear
$ cd non-linear
$ hg debugdrawdag <<'EOF'
> D E
> |\|
> B C
> |/
> A
> EOF
$ hg phase --public C
$ hg phase --force --secret B
$ hg log -G -T '{node|short} {desc} {phase}\n'
o 03ca77807e91 E draft
|
| o 4e4f9194f9f1 D secret
|/|
o | dc0947a82db8 C public
| |
| o 112478962961 B secret
|/
o 426bada5c675 A public
Restore bundle of entire repo
$ hg bundle -a bundle
5 changesets found
$ hg debugbundle bundle
Stream params: {Compression: BZ}
changegroup -- {nbchanges: 5, targetphase: 2, version: 02} (mandatory: True)
426bada5c67598ca65036d57d9e4b64b0c1ce7a0
112478962961147124edd43549aedd1a335e44bf
dc0947a82db884575bb76ea10ac97b08536bfa03
4e4f9194f9f181c57f62e823e8bdfa46ab9e4ff4
03ca77807e919db8807c3749086dc36fb478cac0
cache:rev-branch-cache -- {} (mandatory: False)
phase-heads -- {} (mandatory: True)
dc0947a82db884575bb76ea10ac97b08536bfa03 public
03ca77807e919db8807c3749086dc36fb478cac0 draft
$ hg strip --no-backup A
$ hg unbundle -q bundle
$ rm bundle
$ hg log -G -T '{node|short} {desc} {phase}\n'
o 03ca77807e91 E draft
|
| o 4e4f9194f9f1 D secret
|/|
o | dc0947a82db8 C public
| |
| o 112478962961 B secret
|/
o 426bada5c675 A public
$ hg bundle --base 'A + C' -r D bundle
2 changesets found
$ hg debugbundle bundle
Stream params: {Compression: BZ}
changegroup -- {nbchanges: 2, targetphase: 2, version: 02} (mandatory: True)
112478962961147124edd43549aedd1a335e44bf
4e4f9194f9f181c57f62e823e8bdfa46ab9e4ff4
cache:rev-branch-cache -- {} (mandatory: False)
phase-heads -- {} (mandatory: True)
$ rm bundle
$ hg bundle --base A -r D bundle
3 changesets found
$ hg debugbundle bundle
Stream params: {Compression: BZ}
changegroup -- {nbchanges: 3, targetphase: 2, version: 02} (mandatory: True)
112478962961147124edd43549aedd1a335e44bf
dc0947a82db884575bb76ea10ac97b08536bfa03
4e4f9194f9f181c57f62e823e8bdfa46ab9e4ff4
cache:rev-branch-cache -- {} (mandatory: False)
phase-heads -- {} (mandatory: True)
dc0947a82db884575bb76ea10ac97b08536bfa03 public
$ rm bundle
$ hg bundle --base 'B + C' -r 'D + E' bundle
2 changesets found
$ hg debugbundle bundle
Stream params: {Compression: BZ}
changegroup -- {nbchanges: 2, targetphase: 2, version: 02} (mandatory: True)
4e4f9194f9f181c57f62e823e8bdfa46ab9e4ff4
03ca77807e919db8807c3749086dc36fb478cac0
cache:rev-branch-cache -- {} (mandatory: False)
phase-heads -- {} (mandatory: True)
03ca77807e919db8807c3749086dc36fb478cac0 draft
$ rm bundle