Skip to main content

store_open/
store_open.rs

1//! Measures warm-cache store opening, repeated opening, and unchanged refresh on an existing repo.
2use std::path::PathBuf;
3use std::sync::atomic::AtomicBool;
4use std::time::Instant;
5
6use clap::{Parser, ValueEnum};
7use girt::{AlternateLimits, PackLimits, ReadLimits, Repository};
8
9#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
10enum Operation {
11    /// Open the object store once.
12    Open,
13    /// Open the object store eight times.
14    Repeat,
15    /// Refresh an unchanged object store.
16    Refresh,
17    /// Verify all packs after opening.
18    Verify,
19}
20
21#[derive(Parser)]
22#[command(about, long_about = None)]
23struct Args {
24    /// Operation to measure.
25    #[arg(value_enum)]
26    operation: Operation,
27    /// Existing repository to open.
28    path: PathBuf,
29}
30
31fn main() -> Result<(), Box<dyn std::error::Error>> {
32    let args = Args::parse();
33    let operation = args.operation;
34
35    let start = Instant::now();
36    let repository = Repository::open(args.path)?;
37    let head = repository.head()?.id.ok_or("unborn HEAD")?;
38
39    let count = if operation == Operation::Repeat { 8 } else { 1 };
40    for _ in 0..count {
41        let mut objects = repository.objects_with(PackLimits::trusted())?;
42        let measured = Instant::now();
43
44        match operation {
45            Operation::Refresh => {
46                objects.refresh(PackLimits::trusted(), AlternateLimits::default())?
47            }
48            Operation::Open | Operation::Repeat => {}
49            Operation::Verify => objects.verify_packs(&AtomicBool::new(false))?,
50        }
51
52        let object = objects
53            .read_with(head, ReadLimits::trusted())?
54            .ok_or("missing HEAD")?;
55        std::hint::black_box(object);
56
57        if operation == Operation::Refresh {
58            println!("refresh_seconds={:.9}", measured.elapsed().as_secs_f64());
59        }
60    }
61
62    println!("total_seconds={:.9}", start.elapsed().as_secs_f64());
63    Ok(())
64}