1- //! Store throughput : durable writes with and without batching, verified
2- //! reads, target appends, and the record index. Run on a real disk: syncs
3- //! cost nothing on a RAM-backed file system.
1+ //! Benchmarks for the store : durable writes with and without batching,
2+ //! verified reads, target appends, and the record index. Run on a real disk:
3+ //! syncs cost nothing on a RAM-backed file system.
44
55use std:: fs:: File ;
66use std:: io;
@@ -23,7 +23,8 @@ fn main() {
2323 divan:: main ( ) ;
2424}
2525
26- /// Source-code-like content, which compresses like real files do.
26+ /// Returns `len` bytes of source-code-like content, distinct for each
27+ /// `seed`, which compresses like real files do.
2728fn content ( len : usize , seed : usize ) -> Vec < u8 > {
2829 format ! ( "fn item_{seed}() -> usize {{ {seed} }}\n " )
2930 . into_bytes ( )
@@ -46,8 +47,8 @@ fn store_on<P: Platform>(platform: P) -> (tempfile::TempDir, Store<P>) {
4647 ( dir, store)
4748}
4849
49- /// Writing new objects one batch each: a file and a directory sync per
50- /// object.
50+ /// Writing new objects one batch each, which costs a file sync and a
51+ /// directory sync per object.
5152#[ divan:: bench( args = [ 4 * 1024 , 1024 * 1024 ] , sample_count = 20 ) ]
5253fn write_unbatched ( bencher : Bencher < ' _ , ' _ > , len : usize ) {
5354 let ( _dir, store) = store ( ) ;
@@ -61,8 +62,8 @@ fn write_unbatched(bencher: Bencher<'_, '_>, len: usize) {
6162 . bench_local_refs ( |object| store. write_all ( slice:: from_ref ( object) ) . unwrap ( ) ) ;
6263}
6364
64- /// Writing new 4 KiB objects in one batch, staged from every core: the
65- /// first snapshot of a tree of that many files.
65+ /// Writing `count` new 4 KiB objects in one batch, staged from every core,
66+ /// like the first snapshot of a tree of that many files.
6667#[ divan:: bench( args = [ 1_000 , 20_000 ] , sample_count = 5 , sample_size = 1 ) ]
6768fn write_batch ( bencher : Bencher < ' _ , ' _ > , count : usize ) {
6869 let objects: Vec < _ > = ( 0 ..count)
@@ -75,7 +76,7 @@ fn write_batch(bencher: Bencher<'_, '_>, count: usize) {
7576}
7677
7778/// Walking a store of 20k objects for the temporary files crashed writes
78- /// left: what garbage collection pays .
79+ /// left behind, as garbage collection does .
7980#[ divan:: bench( sample_count = 20 ) ]
8081fn remove_stale_temps ( bencher : Bencher < ' _ , ' _ > ) {
8182 let ( _dir, store) = store ( ) ;
@@ -86,9 +87,9 @@ fn remove_stale_temps(bencher: Bencher<'_, '_>) {
8687 bencher. bench ( || store. remove_stale_temps ( ) . unwrap ( ) ) ;
8788}
8889
89- /// Writing objects the store already has: the common case when
90- /// snapshotting. The batch syncs the directory of each, for the writer that
91- /// renamed it there may not have yet.
90+ /// Writing objects the store already has, the common case when
91+ /// snapshotting. The batch still syncs each object's directory, since the
92+ /// writer that put the object there may not have synced it yet.
9293#[ divan:: bench( args = [ 1 , 1_000 , 20_000 ] ) ]
9394fn write_existing ( bencher : Bencher < ' _ , ' _ > , count : usize ) {
9495 let ( _dir, store) = store ( ) ;
@@ -101,7 +102,7 @@ fn write_existing(bencher: Bencher<'_, '_>, count: usize) {
101102 . bench ( || store. write_all ( black_box ( & objects) ) . unwrap ( ) ) ;
102103}
103104
104- /// Reading, decompressing, and verifying objects: the cost of checkouts.
105+ /// Reading, decompressing and verifying an object, as checkouts do .
105106#[ divan:: bench( args = [ 4 * 1024 , 1024 * 1024 ] ) ]
106107fn read ( bencher : Bencher < ' _ , ' _ > , len : usize ) {
107108 let ( _dir, store) = store ( ) ;
@@ -112,7 +113,7 @@ fn read(bencher: Bencher<'_, '_>, len: usize) {
112113 . bench ( || store. read ( black_box ( object. id ( ) ) ) . unwrap ( ) ) ;
113114}
114115
115- /// Appending an acceptance to a target: the durable part of every landing.
116+ /// Appending an acceptance to a target, the durable step of every landing.
116117#[ divan:: bench( sample_count = 20 ) ]
117118fn append ( bencher : Bencher < ' _ , ' _ > ) {
118119 let ( _dir, store) = store ( ) ;
@@ -135,9 +136,10 @@ fn append(bencher: Bencher<'_, '_>) {
135136 } ) ;
136137}
137138
138- /// `count` records, as a busy repository receives them: a revision of one
139- /// of a hundred changes, evolving from that change's previous one, then nine
140- /// statements about it.
139+ /// Returns `count` records like a busy repository receives them: every
140+ /// tenth is a revision of one of a hundred changes, in turn, evolving from
141+ /// that change's previous revision, and the nine after it are statements
142+ /// about it.
141143fn records ( count : usize ) -> Vec < EncodedObject > {
142144 let snapshot = TreeId :: from ( Tree :: default ( ) . encode ( ) . id ( ) ) ;
143145 let mut heads = vec ! [ None ; 100 ] ;
@@ -176,7 +178,7 @@ fn records(count: usize) -> Vec<EncodedObject> {
176178 . collect ( )
177179}
178180
179- /// The native platform without syncs , to measure what syncs hide .
181+ /// The native platform with every sync skipped , to measure what syncs cost .
180182#[ derive( Clone , Copy , Debug , Default ) ]
181183struct NoSync ;
182184
@@ -211,9 +213,9 @@ impl FileSystem for NoSync {
211213}
212214
213215/// Writing new records in one batch, which indexes them, against blobs of
214- /// the same content , which aren't indexed: the difference is what indexing
215- /// costs, which [`NoSync`] shows apart from the syncs. One record is what
216- /// issuing a statement costs .
216+ /// the same bytes , which aren't indexed. The difference is what indexing
217+ /// costs; [`NoSync`] shows it without the syncs. One record is the cost of
218+ /// issuing a statement.
217219#[ divan:: bench(
218220 types = [ Native , NoSync ] ,
219221 consts = [ true , false ] ,
0 commit comments