rust: peek_mut optim for lazy ancestors
This is one of the two optimizations that are also
present in the Python code: replacing pairs of pop/push
on the BinaryHeap by single updates, hence having it
under the hood maintain its consistency (sift) only once.
On Mozilla central, the measured gain (see details below)
is around 7%.
Creating the PeekMut object by calling peek_mut() right away
instead of peek() first is less efficient (gain is only 4%, stats
not included).
Our interpretation is that its creation has a cost which is vasted
in the cases where it ends by droping the value (Peekmut::pop()
just does self.heap.pop() anyway). On the other hand, the immutable
peek() is very fast: it's just taking a reference in the
underlying vector.
The Python version still has another optimization:
if parent(current) == current-1, then the heap doesn't need
to maintain its consistency, since we already know that
it's bigger than all the others in the heap.
Rust's BinaryHeap doesn't allow us to mutate its biggest
element with no housekeeping, but we tried it anyway, with a
copy of the BinaryHeap implementation with a dedicaded added
method: it's not worth the technical debt in our opinion
(we measured only a further 1.6% improvement).
One possible explanation would be that the sift is really fast
anyway in that case, whereas it's not in the case of Python,
because it's at least partly done in slow Python code.
Still it's possible that replacing BinaryHeap by something more
dedicated to discrete ordered types could be faster.
Measurements on mozilla-central:
Three runs of 'hg perfancestors' on the parent changeset:
Moyenne des médianes: 0.100587
! wall 0.100062 comb 0.100000 user 0.100000 sys 0.000000 (best of 98)
! wall 0.135804 comb 0.130000 user 0.130000 sys 0.000000 (max of 98)
! wall 0.102864 comb 0.102755 user 0.099286 sys 0.003469 (avg of 98)
! wall 0.101486 comb 0.110000 user 0.110000 sys 0.000000 (median of 98)
! wall 0.096804 comb 0.090000 user 0.090000 sys 0.000000 (best of 100)
! wall 0.132235 comb 0.130000 user 0.120000 sys 0.010000 (max of 100)
! wall 0.100258 comb 0.100300 user 0.096000 sys 0.004300 (avg of 100)
! wall 0.098384 comb 0.100000 user 0.100000 sys 0.000000 (median of 100)
! wall 0.099925 comb 0.100000 user 0.100000 sys 0.000000 (best of 98)
! wall 0.133518 comb 0.140000 user 0.130000 sys 0.010000 (max of 98)
! wall 0.102381 comb 0.102449 user 0.098265 sys 0.004184 (avg of 98)
! wall 0.101891 comb 0.090000 user 0.090000 sys 0.000000 (median of 98)
Mean of the medians: 0.100587
On the present changeset:
! wall 0.091344 comb 0.090000 user 0.090000 sys 0.000000 (best of 100)
! wall 0.122728 comb 0.120000 user 0.110000 sys 0.010000 (max of 100)
! wall 0.093268 comb 0.093300 user 0.089300 sys 0.004000 (avg of 100)
! wall 0.092567 comb 0.100000 user 0.090000 sys 0.010000 (median of 100)
! wall 0.093294 comb 0.080000 user 0.080000 sys 0.000000 (best of 100)
! wall 0.144887 comb 0.150000 user 0.140000 sys 0.010000 (max of 100)
! wall 0.097708 comb 0.097700 user 0.093400 sys 0.004300 (avg of 100)
! wall 0.094980 comb 0.100000 user 0.090000 sys 0.010000 (median of 100)
! wall 0.091262 comb 0.090000 user 0.080000 sys 0.010000 (best of 100)
! wall 0.123772 comb 0.130000 user 0.120000 sys 0.010000 (max of 100)
! wall 0.093188 comb 0.093200 user 0.089300 sys 0.003900 (avg of 100)
! wall 0.092364 comb 0.100000 user 0.090000 sys 0.010000 (median of 100)
Mean of the medians is 0.0933
Differential Revision: https://phab.mercurial-scm.org/D5358
#require reporevlogstore
prepare repo
$ hg init a
$ cd a
$ echo "some text" > FOO.txt
$ echo "another text" > bar.txt
$ echo "more text" > QUICK.txt
$ hg add
adding FOO.txt
adding QUICK.txt
adding bar.txt
$ hg ci -mtest1
verify
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
checked 1 changesets with 3 changes to 3 files
verify with journal
$ touch .hg/store/journal
$ hg verify
abandoned transaction found - run hg recover
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
checked 1 changesets with 3 changes to 3 files
$ rm .hg/store/journal
introduce some bugs in repo
$ cd .hg/store/data
$ mv _f_o_o.txt.i X_f_o_o.txt.i
$ mv bar.txt.i xbar.txt.i
$ rm _q_u_i_c_k.txt.i
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
warning: revlog 'data/FOO.txt.i' not in fncache!
0: empty or missing FOO.txt
FOO.txt@0: manifest refers to unknown revision f62022d3d590
warning: revlog 'data/QUICK.txt.i' not in fncache!
0: empty or missing QUICK.txt
QUICK.txt@0: manifest refers to unknown revision 88b857db8eba
warning: revlog 'data/bar.txt.i' not in fncache!
0: empty or missing bar.txt
bar.txt@0: manifest refers to unknown revision 256559129457
checked 1 changesets with 0 changes to 3 files
3 warnings encountered!
hint: run "hg debugrebuildfncache" to recover from corrupt fncache
6 integrity errors encountered!
(first damaged changeset appears to be 0)
[1]
$ cd ../../..
$ cd ..
Set up a repo for testing missing revlog entries
$ hg init missing-entries
$ cd missing-entries
$ echo 0 > file
$ hg ci -Aqm0
$ cp -R .hg/store .hg/store-partial
$ echo 1 > file
$ hg ci -Aqm1
$ cp -R .hg/store .hg/store-full
Entire changelog missing
$ rm .hg/store/00changelog.*
$ hg verify -q
0: empty or missing changelog
manifest@0: d0b6632564d4 not in changesets
manifest@1: 941fc4534185 not in changesets
3 integrity errors encountered!
(first damaged changeset appears to be 0)
[1]
$ cp -R .hg/store-full/. .hg/store
Entire manifest log missing
$ rm .hg/store/00manifest.*
$ hg verify -q
0: empty or missing manifest
1 integrity errors encountered!
(first damaged changeset appears to be 0)
[1]
$ cp -R .hg/store-full/. .hg/store
Entire filelog missing
$ rm .hg/store/data/file.*
$ hg verify -q
warning: revlog 'data/file.i' not in fncache!
0: empty or missing file
file@0: manifest refers to unknown revision 362fef284ce2
file@1: manifest refers to unknown revision c10f2164107d
1 warnings encountered!
hint: run "hg debugrebuildfncache" to recover from corrupt fncache
3 integrity errors encountered!
(first damaged changeset appears to be 0)
[1]
$ cp -R .hg/store-full/. .hg/store
Entire changelog and manifest log missing
$ rm .hg/store/00changelog.*
$ rm .hg/store/00manifest.*
$ hg verify -q
warning: orphan data file 'data/file.i'
1 warnings encountered!
$ cp -R .hg/store-full/. .hg/store
Entire changelog and filelog missing
$ rm .hg/store/00changelog.*
$ rm .hg/store/data/file.*
$ hg verify -q
0: empty or missing changelog
manifest@0: d0b6632564d4 not in changesets
manifest@1: 941fc4534185 not in changesets
warning: revlog 'data/file.i' not in fncache!
?: empty or missing file
file@0: manifest refers to unknown revision 362fef284ce2
file@1: manifest refers to unknown revision c10f2164107d
1 warnings encountered!
hint: run "hg debugrebuildfncache" to recover from corrupt fncache
6 integrity errors encountered!
(first damaged changeset appears to be 0)
[1]
$ cp -R .hg/store-full/. .hg/store
Entire manifest log and filelog missing
$ rm .hg/store/00manifest.*
$ rm .hg/store/data/file.*
$ hg verify -q
0: empty or missing manifest
warning: revlog 'data/file.i' not in fncache!
0: empty or missing file
1 warnings encountered!
hint: run "hg debugrebuildfncache" to recover from corrupt fncache
2 integrity errors encountered!
(first damaged changeset appears to be 0)
[1]
$ cp -R .hg/store-full/. .hg/store
Changelog missing entry
$ cp -f .hg/store-partial/00changelog.* .hg/store
$ hg verify -q
manifest@?: rev 1 points to nonexistent changeset 1
manifest@?: 941fc4534185 not in changesets
file@?: rev 1 points to nonexistent changeset 1
(expected 0)
1 warnings encountered!
3 integrity errors encountered!
[1]
$ cp -R .hg/store-full/. .hg/store
Manifest log missing entry
$ cp -f .hg/store-partial/00manifest.* .hg/store
$ hg verify -q
manifest@1: changeset refers to unknown revision 941fc4534185
file@1: c10f2164107d not in manifests
2 integrity errors encountered!
(first damaged changeset appears to be 1)
[1]
$ cp -R .hg/store-full/. .hg/store
Filelog missing entry
$ cp -f .hg/store-partial/data/file.* .hg/store/data
$ hg verify -q
file@1: manifest refers to unknown revision c10f2164107d
1 integrity errors encountered!
(first damaged changeset appears to be 1)
[1]
$ cp -R .hg/store-full/. .hg/store
Changelog and manifest log missing entry
$ cp -f .hg/store-partial/00changelog.* .hg/store
$ cp -f .hg/store-partial/00manifest.* .hg/store
$ hg verify -q
file@?: rev 1 points to nonexistent changeset 1
(expected 0)
file@?: c10f2164107d not in manifests
1 warnings encountered!
2 integrity errors encountered!
[1]
$ cp -R .hg/store-full/. .hg/store
Changelog and filelog missing entry
$ cp -f .hg/store-partial/00changelog.* .hg/store
$ cp -f .hg/store-partial/data/file.* .hg/store/data
$ hg verify -q
manifest@?: rev 1 points to nonexistent changeset 1
manifest@?: 941fc4534185 not in changesets
file@?: manifest refers to unknown revision c10f2164107d
3 integrity errors encountered!
[1]
$ cp -R .hg/store-full/. .hg/store
Manifest and filelog missing entry
$ cp -f .hg/store-partial/00manifest.* .hg/store
$ cp -f .hg/store-partial/data/file.* .hg/store/data
$ hg verify -q
manifest@1: changeset refers to unknown revision 941fc4534185
1 integrity errors encountered!
(first damaged changeset appears to be 1)
[1]
$ cp -R .hg/store-full/. .hg/store
Corrupt changelog base node to cause failure to read revision
$ printf abcd | dd conv=notrunc of=.hg/store/00changelog.i bs=1 seek=16 \
> 2> /dev/null
$ hg verify -q
0: unpacking changeset 08b1860757c2: * (glob)
manifest@?: rev 0 points to unexpected changeset 0
manifest@?: d0b6632564d4 not in changesets
file@?: rev 0 points to unexpected changeset 0
(expected 1)
1 warnings encountered!
4 integrity errors encountered!
(first damaged changeset appears to be 0)
[1]
$ cp -R .hg/store-full/. .hg/store
Corrupt manifest log base node to cause failure to read revision
$ printf abcd | dd conv=notrunc of=.hg/store/00manifest.i bs=1 seek=16 \
> 2> /dev/null
$ hg verify -q
manifest@0: reading delta d0b6632564d4: * (glob)
file@0: 362fef284ce2 not in manifests
2 integrity errors encountered!
(first damaged changeset appears to be 0)
[1]
$ cp -R .hg/store-full/. .hg/store
Corrupt filelog base node to cause failure to read revision
$ printf abcd | dd conv=notrunc of=.hg/store/data/file.i bs=1 seek=16 \
> 2> /dev/null
$ hg verify -q
file@0: unpacking 362fef284ce2: * (glob)
1 integrity errors encountered!
(first damaged changeset appears to be 0)
[1]
$ cp -R .hg/store-full/. .hg/store
$ cd ..
test changelog without a manifest
$ hg init b
$ cd b
$ hg branch foo
marked working directory as branch foo
(branches are permanent and global, did you want a bookmark?)
$ hg ci -m branchfoo
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
checked 1 changesets with 0 changes to 0 files
test revlog corruption
$ touch a
$ hg add a
$ hg ci -m a
$ echo 'corrupted' > b
$ dd if=.hg/store/data/a.i of=start bs=1 count=20 2>/dev/null
$ cat start b > .hg/store/data/a.i
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
a@1: broken revlog! (index data/a.i is corrupted)
warning: orphan data file 'data/a.i'
checked 2 changesets with 0 changes to 1 files
1 warnings encountered!
1 integrity errors encountered!
(first damaged changeset appears to be 1)
[1]
$ cd ..
test revlog format 0
$ revlog-formatv0.py
$ cd formatv0
$ hg verify
repository uses revlog format 0
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
checked 1 changesets with 1 changes to 1 files
$ cd ..
test flag processor and skipflags
$ hg init skipflags
$ cd skipflags
$ cat >> .hg/hgrc <<EOF
> [extensions]
> flagprocessor=$RUNTESTDIR/flagprocessorext.py
> EOF
$ echo '[BASE64]content' > base64
$ hg commit -Aqm 'flag processor content' base64
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
checked 1 changesets with 1 changes to 1 files
$ cat >> $TESTTMP/break-base64.py <<EOF
> from __future__ import absolute_import
> import base64
> base64.b64decode=lambda x: x
> EOF
$ cat >> .hg/hgrc <<EOF
> breakbase64=$TESTTMP/break-base64.py
> EOF
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
base64@0: unpacking 794cee7777cb: integrity check failed on data/base64.i:0
checked 1 changesets with 1 changes to 1 files
1 integrity errors encountered!
(first damaged changeset appears to be 0)
[1]
$ hg verify --config verify.skipflags=2147483647
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
checked 1 changesets with 1 changes to 1 files