Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 134 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions crates/aube-lockfile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ blake3 = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
smallvec = { workspace = true }
memchr = "2"

[features]
# Exposes the `__bench_parse_*` shims used by the `pnpm_lock_parse`
# bench. Off by default so the bench helpers stay out of the crate's
# public API surface.
bench = []

[dev-dependencies]
proptest = "1"
tempfile = "3"
criterion = { version = "0.5", default-features = false }

[[bench]]
name = "pnpm_lock_parse"
harness = false
required-features = ["bench"]
40 changes: 40 additions & 0 deletions crates/aube-lockfile/benches/pnpm_lock_parse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Old-vs-new parse benchmark for `pnpm-lock.yaml`.
//!
//! Compares the general `yaml_serde` parse path against the byte-cursor
//! subset parser on a large generated lockfile. Set
//! `AUBE_BENCH_LOCKFILE=/path/to/pnpm-lock.yaml` to point at a real
//! lockfile instead of the bundled small fixture.

use aube_lockfile::pnpm;
use criterion::{Criterion, criterion_group, criterion_main};
use std::hint::black_box;

fn load() -> String {
if let Ok(p) = std::env::var("AUBE_BENCH_LOCKFILE") {
return std::fs::read_to_string(p).expect("read AUBE_BENCH_LOCKFILE");
}
include_str!("../tests/fixtures/pnpm-native.yaml").to_string()
}

fn bench(c: &mut Criterion) {
let content = load();
eprintln!("benchmarking pnpm-lock.yaml: {} bytes", content.len());

// Sanity: both paths must agree on the structure they parse.
let s = pnpm::__bench_parse_subset(&content);
let y = pnpm::__bench_parse_serde(&content);
assert!(s.is_some(), "subset parser declined the bench input");
assert_eq!(s, y, "subset and serde parsers disagree on counts");

let mut g = c.benchmark_group("pnpm-lock-parse");
g.bench_function("serde", |b| {
b.iter(|| black_box(pnpm::__bench_parse_serde(black_box(&content))))
});
g.bench_function("subset", |b| {
b.iter(|| black_box(pnpm::__bench_parse_subset(black_box(&content))))
});
g.finish();
}

criterion_group!(benches, bench);
criterion_main!(benches);
21 changes: 21 additions & 0 deletions crates/aube-lockfile/src/pnpm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod dep_path;
mod format;
mod raw;
mod read;
mod subset;
mod write;

#[cfg(test)]
Expand All @@ -12,6 +13,26 @@ pub use checksum::{package_extensions_checksum, pnpmfile_checksum};
pub use read::parse;
pub use write::write;

/// Benchmark-only shims comparing the byte-cursor subset parser against
/// the general `yaml_serde` parser on raw `pnpm-lock.yaml` content.
/// Returns `(packages, snapshots, importers)` counts so the bench's
/// black-box can't be optimized away. Gated behind the `bench` feature
/// so they are not part of the crate's default public surface.
#[cfg(feature = "bench")]
#[doc(hidden)]
pub fn __bench_parse_subset(content: &str) -> Option<(usize, usize, usize)> {
subset::try_parse(content).map(|r| raw::__bench_counts(&r))
}

/// Benchmark-only: parse via the original serde path.
#[cfg(feature = "bench")]
#[doc(hidden)]
pub fn __bench_parse_serde(content: &str) -> Option<(usize, usize, usize)> {
raw::parse_raw_lockfile_serde(content)
.ok()
.map(|r| raw::__bench_counts(&r))
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

pub(super) fn tarball_url_is_hosted_git(url: &str) -> bool {
let Some((host, path)) = http_url_host_and_path(url) else {
return false;
Expand Down
Loading
Loading