···11+extern crate repo_stream;
22+use futures::TryStreamExt;
33+use iroh_car::CarReader;
44+use std::convert::Infallible;
55+use std::path::{Path, PathBuf};
66+77+use criterion::{Criterion, criterion_group, criterion_main};
88+99+pub fn criterion_benchmark(c: &mut Criterion) {
1010+ let rt = tokio::runtime::Builder::new_multi_thread()
1111+ .enable_all()
1212+ .build()
1313+ .expect("Creating runtime failed");
1414+1515+ let filename = std::env::var("HUGE_CAR").expect("HUGE_CAR env var");
1616+ let filename: PathBuf = filename.try_into().unwrap();
1717+1818+ c.bench_function("huge-car", |b| {
1919+ b.to_async(&rt).iter(async || drive_car(&filename).await)
2020+ });
2121+}
2222+2323+async fn drive_car(filename: impl AsRef<Path>) {
2424+ let reader = tokio::fs::File::open(filename).await.unwrap();
2525+ let reader = tokio::io::BufReader::new(reader);
2626+ let reader = CarReader::new(reader).await.unwrap();
2727+2828+ let root = reader
2929+ .header()
3030+ .roots()
3131+ .first()
3232+ .ok_or("missing root")
3333+ .unwrap()
3434+ .clone();
3535+3636+ let stream = std::pin::pin!(reader.stream());
3737+3838+ let (_commit, v) =
3939+ repo_stream::drive::Vehicle::init(root, stream, |block| Ok::<_, Infallible>(block.len()))
4040+ .await
4141+ .unwrap();
4242+ let mut record_stream = std::pin::pin!(v.stream());
4343+4444+ while let Some(_) = record_stream.try_next().await.unwrap() {
4545+ // just here for the drive
4646+ }
4747+}
4848+4949+criterion_group!(benches, criterion_benchmark);
5050+criterion_main!(benches);
+19-2
readme.md
···33Fast and (aspirationally) robust atproto CAR file processing in rust
445566+current car processing times (records processed into their length usize, phil's dev machine):
77+88+- 128MiB CAR file: `347ms`
99+- 5.0MiB: `6.1ms`
1010+- 279KiB: `139us`
1111+- 3.4KiB: `4.9us`
1212+1313+1414+running the huge-car benchmark
1515+1616+- to avoid committing it to the repo, you have to pass it in through the env for now.
1717+1818+ ```bash
1919+ HUGE_CAR=~/Downloads/did_plc_redacted.car cargo bench -- huge-car
2020+ ```
2121+2222+623todo
72488-- [ ] car file test fixtures & validation tests
2525+- [x] car file test fixtures & validation tests
926- [ ] make sure we can get the did and signature out for verification
1027- [ ] spec compliance todos
1128 - [ ] assert that keys are ordered and fail if not
···1330- [ ] performance todos
1431 - [ ] consume the serialized nodes into a mutable efficient format
1532 - [ ] maybe customize the deserialize impl to do that directly?
1616- - [ ] benchmark and profile
3333+ - [x] benchmark and profile
1734- [ ] robustness todos
1835 - [ ] swap the blocks hashmap for a BlockStore trait that can be dumped to redb
1936 - [ ] maybe keep the redb function behind a feature flag?