Skip to content

Commit 3dfceb8

Browse files
committed
docs(store): say plainly what each item does
Rewrites the doc comments of these files so each says plainly what its item does, without design asides. Code and code examples are unchanged.
1 parent aaaecfb commit 3dfceb8

6 files changed

Lines changed: 290 additions & 320 deletions

File tree

‎apps/origin-src/benches/packs.rs‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! Packs: writing and reading a million statements loose and packed,
2-
//! compacting them, and looking objects up across several packs. Run on a
3-
//! real disk: syncs cost nothing on a RAM-backed file system.
1+
//! Benchmarks for packs: writing and reading a million statements loose and
2+
//! packed, compacting them, and finding objects across several packs. Run
3+
//! on a real disk: syncs cost nothing on a RAM-backed file system.
44
55
use std::path::PathBuf;
66
use std::sync::{LazyLock, OnceLock};
@@ -25,7 +25,8 @@ static ROOT: OnceLock<PathBuf> = OnceLock::new();
2525
/// How many statements the large stores hold.
2626
const STATEMENTS: usize = 1_000_000;
2727

28-
/// `count` distinct statements, like a CI runner issues, from `seed` on.
28+
/// Returns `count` distinct statements, like those a CI runner issues,
29+
/// numbered from `seed`.
2930
fn statements(seed: usize, count: usize) -> Vec<EncodedObject> {
3031
(seed..seed + count)
3132
.map(|seed| {
@@ -57,17 +58,16 @@ fn store() -> Fixture {
5758
(dir, store)
5859
}
5960

60-
/// A store of the million statements, loose.
61+
/// A store holding the million statements as loose objects.
6162
fn loose() -> Fixture {
6263
let (dir, store) = store();
6364
store.write_all(&STATEMENTS_1M).unwrap();
6465
(dir, store)
6566
}
6667

67-
/// A store of the million statements in `packs` packs, halving in size so
68-
/// compaction keeps them apart. The first pack takes the remainder: each
69-
/// later one is then at most half the one before, which compaction never
70-
/// merges into it.
68+
/// A store holding the million statements in `packs` packs. Each pack after
69+
/// the first is at most half the size of the one before, so compaction never
70+
/// merges them. The first pack takes the remainder.
7171
fn packed(packs: u32) -> Fixture {
7272
let (dir, store) = store();
7373
let later: usize = (1..packs).map(|pack| STATEMENTS >> (pack + 1)).sum();
@@ -103,7 +103,7 @@ static PACKED: [LazyLock<Fixture, fn() -> Fixture>; 3] = [
103103
LazyLock::new(|| packed(16)),
104104
];
105105

106-
/// The large packed store with `packs` packs.
106+
/// The packed store with `packs` packs: 1, 4 or 16.
107107
fn packed_store(packs: u32) -> &'static Store {
108108
let index = match packs {
109109
1 => 0,
@@ -125,8 +125,7 @@ fn write_loose(bencher: Bencher<'_, '_>) {
125125
.bench_local_refs(|(_, store)| store.write_all(&STATEMENTS_1M).unwrap());
126126
}
127127

128-
/// Compacting a million loose statements into one pack: what packing costs
129-
/// on top of writing them loose.
128+
/// Compacting a million loose statements into one pack.
130129
#[divan::bench(sample_count = 3, sample_size = 1)]
131130
fn compact(bencher: Bencher<'_, '_>) {
132131
bencher
@@ -135,8 +134,8 @@ fn compact(bencher: Bencher<'_, '_>) {
135134
.bench_local_refs(|(_, store)| store.compact().unwrap());
136135
}
137136

138-
/// Reading back every statement of a million, in id order, from one
139-
/// thread.
137+
/// Reading every statement of a million back, in id order, from one thread,
138+
/// loose or packed.
140139
#[divan::bench(args = ["loose", "packed"], sample_count = 3, sample_size = 1)]
141140
fn read_all(bencher: Bencher<'_, '_>, layout: &str) {
142141
let store = match layout {
@@ -152,7 +151,7 @@ fn read_all(bencher: Bencher<'_, '_>, layout: &str) {
152151
});
153152
}
154153

155-
/// Reading one statement of a million, loose or in the smallest of
154+
/// Reading one statement of a million, loose or from the smallest of
156155
/// `packs` packs, which is searched last.
157156
#[divan::bench(args = [0, 1, 4, 16])]
158157
fn read_one(bencher: Bencher<'_, '_>, packs: u32) {
@@ -167,8 +166,8 @@ fn read_one(bencher: Bencher<'_, '_>, packs: u32) {
167166
}
168167

169168
/// Looking up an object the store doesn't have, among a million statements
170-
/// loose or in `packs` packs: every pack is searched and the manifest
171-
/// reread.
169+
/// loose or in `packs` packs. Every pack is searched and the manifest is
170+
/// read again.
172171
#[divan::bench(args = [0, 1, 4, 16])]
173172
fn contains_absent(bencher: Bencher<'_, '_>, packs: u32) {
174173
let store = if packs == 0 {

‎apps/origin-src/benches/snapshot.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//! Snapshotting a working copy: the cost behind every command that reads it.
2-
//! Objects are written durably, as the commands write them.
1+
//! Benchmarks for snapshotting a working copy, which every command that
2+
//! reads the working copy does. Objects are written durably, as the commands
3+
//! write them.
34
45
use std::sync::atomic::{AtomicU64, Ordering};
56

‎apps/origin-src/benches/store.rs‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
55
use std::fs::File;
66
use 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.
2728
fn 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)]
5253
fn 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)]
6768
fn 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)]
8081
fn 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])]
9394
fn 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])]
106107
fn 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)]
117118
fn 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.
141143
fn 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)]
181183
struct 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

Comments
 (0)