Skip to content

Commit d16521b

Browse files
committed
clippy, workspace deps, upgrades, fmt
1 parent 0ffde43 commit d16521b

16 files changed

Lines changed: 278 additions & 277 deletions

File tree

Cargo.lock

Lines changed: 180 additions & 133 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
[workspace]
32
members = ["crates/*"]
43
resolver = "2"
@@ -24,6 +23,28 @@ resolver = "2"
2423
repository = "https://github.com/spanishpear/berry"
2524
# version = "0.1.0"
2625

26+
[workspace.dependencies]
27+
berry-core = { path = "crates/berry-core" }
28+
berry-test = { path = "crates/berry-test" }
29+
# https://nodejs.org/api/n-api.html#node-api-version-matrix
30+
# support node 18-22
31+
clap = { version = "4.5.45", features = ["derive"] }
32+
criterion = { version = "0.7", features = ["html_reports"] }
33+
memory-stats = { version = "1.2.0" }
34+
napi = { version = "3.2.4", default-features = false, features = ["napi9"] }
35+
napi-derive = { version = "3.2.4", default-features = false, features = [
36+
"type-def",
37+
] }
38+
nom = { version = "8.0.0" }
39+
rstest = { version = "0.26" }
40+
serde = { version = "1.0", features = ["derive"] }
41+
serde_json = { version = "1.0" }
42+
43+
[workspace.dev-dependencies]
44+
pretty_assertions = { version = "1.4" }
45+
rstest = { version = "0.26" }
46+
47+
2748
# https://doc.rust-lang.org/rustc/lints/groups.html
2849
[workspace.lints.rust]
2950
deprecated-safe = "warn"
@@ -46,23 +67,13 @@ resolver = "2"
4667
pedantic = { level = "warn", priority = -1 } # default is "allow"
4768
# Now, allow ones we want to ignore
4869
cargo_common_metadata = "allow"
70+
cast_precision_loss = "allow" # not super important right now
4971
implicit_return = "allow" # Prefer idiomatic rust
5072
missing_const_for_fn = "allow"
5173
missing_errors_doc = "allow"
5274
missing_panics_doc = "allow"
5375
must_use_candidate = "allow"
5476

55-
[workspace.dependencies]
56-
# https://nodejs.org/api/n-api.html#node-api-version-matrix
57-
# support node 18-22
58-
napi = { version = "3.0.0-alpha", default-features = false, features = [
59-
"napi9",
60-
] }
61-
napi-derive = { version = "3.0.0-alpha", default-features = false, features = [
62-
"type-def",
63-
] }
64-
nom = "8.0.0"
65-
6677
[profile.release]
6778
codegen-units = 1
6879
lto = true

README.md

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
# Berry - High-Performance Yarn Lockfile Parser
22

3-
A high-performance, zero-allocation parser for Yarn v3/v4 lockfiles, built with Rust and nom. This parser focuses on idiomatic Rust, modularity, and performance for future use in WASM or with napi-rs.
3+
A high-performance parser for Yarn v3/v4 lockfiles, built with Rust and nom. This parser focuses on performance, with minimal allocation and future use in WASM or with napi-rs.
44

5-
## 🚀 Features
6-
7-
- **Zero-Allocation Parsing**: Minimal memory allocations during parsing phase
8-
- **High Performance**: Sub-millisecond parsing for most lockfiles
9-
- **Comprehensive Support**: Handles all major Yarn v3/v4 lockfile features
10-
- **Memory Efficient**: Optimized for minimal heap usage
11-
- **Production Ready**: Comprehensive test coverage and benchmarking
12-
13-
## 📊 Performance
5+
## Performance
146

157
The parser is designed for high performance with minimal memory usage:
168

17-
- **Small files** (~1KB): ~6-7 microseconds
18-
- **Medium files** (~2KB): ~2-3 microseconds
19-
- **Large files** (~40KB): ~5 microseconds
20-
- **Memory usage**: Typically 0-20KB heap usage depending on fixture complexity
9+
- Small files (~1KB): ~6-7 microseconds
10+
- Medium files (~2KB): ~2-3 microseconds
11+
- Large files (~40KB): ~5 microseconds
12+
- Memory usage: Typically 0-20KB heap usage depending on fixture complexity
2113

22-
## 🏗️ Architecture
14+
## Architecture
2315

2416
```
2517
crates/
2618
├── berry-core/ # Main parser library
2719
├── berry-test/ # Integration tests
2820
├── berry-bench/ # Criterion microbenchmarks
2921
├── berry-bench-bin/ # CLI benchmarking tool
30-
└── node-bindings/ # Node.js bindings (planned)
22+
└── node-bindings/ # Node.js bindings (WIP)
3123
```
3224

33-
## 🧪 Benchmarking
25+
## Benchmarking
3426

35-
The project includes comprehensive benchmarking infrastructure for performance monitoring and regression detection.
27+
The project includes basic benchmarking infrastructure for performance monitoring and regression detection. Claude wrote that part, apologies.
3628

3729
### Quick Performance Testing
3830

@@ -59,12 +51,12 @@ cargo bench --package berry-bench --bench parser_benchmarks -- --quick
5951

6052
### Benchmark Categories
6153

62-
- **Fixture Parsing**: Different file sizes and complexities
63-
- **Memory Usage**: Heap usage tracking and analysis
64-
- **Zero-Allocation Validation**: Memory allocation verification
65-
- **Input Characteristics**: Various lockfile formats and features
54+
- Fixture Parsing: Different file sizes and complexities
55+
- Memory Usage: Heap usage tracking and analysis
56+
- Zero-Allocation Validation: Memory allocation verification
57+
- Input Characteristics: Various lockfile formats and features
6658

67-
## 🛠️ Development
59+
## Development
6860

6961
### Prerequisites
7062

@@ -104,7 +96,7 @@ cargo clippy --workspace
10496
cargo fmt --workspace
10597
```
10698

107-
## 📁 Project Structure
99+
## Project Structure
108100

109101
### Core Parser (`crates/berry-core/`)
110102

@@ -127,9 +119,9 @@ cargo fmt --workspace
127119
- Memory usage tracking and heap analysis
128120
- Performance regression detection
129121

130-
## 🎯 Current Status
122+
## Current Status
131123

132-
**Production Ready**
124+
- Production Ready
133125

134126
- All tests passing (23/23)
135127
- Zero clippy warnings
@@ -138,31 +130,31 @@ cargo fmt --workspace
138130
- Modern nom API usage
139131
- Comprehensive test coverage
140132

141-
🔄 **In Development**
133+
- In Development
142134

143135
- Advanced lockfile features (multi-descriptors, meta fields)
144136
- WASM compilation support
145137
- Node.js bindings with napi-rs
146138
- CI/CD benchmarking pipeline
147139

148-
## 📈 Performance Monitoring
140+
## Performance Monitoring
149141

150142
The benchmarking infrastructure automatically detects:
151143

152-
- **Performance regressions** (>50% slower than baseline)
153-
- **Statistical significance** in benchmark results
154-
- **Memory usage patterns** and allocation tracking
155-
- **Zero-allocation violations** during parsing
144+
- Performance regressions (>50% slower than baseline)
145+
- Statistical significance in benchmark results
146+
- Memory usage patterns and allocation tracking
147+
- Zero-allocation violations during parsing
156148

157-
## 🤝 Contributing
149+
## Contributing
158150

159151
See [CONTRIBUTING.md](dev-docs/CONTRIBUTING.md) for development guidelines and benchmarking information.
160152

161-
## 📄 License
153+
## License
162154

163155
MIT OR Apache-2.0
164156

165-
## 🔗 Links
157+
## Links
166158

167159
- [Task List](.cursor/tasks/BERRY_LOCKFILE_PARSER.md) - Detailed development progress
168160
- [Benchmarking Plan](.cursor/tasks/BENCHMARKING_PLAN.md) - Comprehensive benchmarking strategy

crates/berry-bench-bin/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ repository.workspace = true
77
version.workspace = true
88

99
[dependencies]
10-
berry-core = { path = "../berry-core" }
11-
berry-test = { path = "../berry-test" }
12-
clap = { version = "4.0", features = ["derive"] }
13-
memory-stats = "1.1"
14-
serde = { version = "1.0", features = ["derive"] }
15-
serde_json = "1.0"
10+
berry-core = { workspace = true }
11+
berry-test = { workspace = true }
12+
clap = { workspace = true }
13+
memory-stats = { workspace = true }
14+
serde = { workspace = true }
15+
serde_json = { workspace = true }
1616

1717
[lints]
1818
workspace = true

crates/berry-bench-bin/src/main.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ fn benchmark_fixture(
112112
let result = parse_lockfile(&fixture);
113113
let after = memory_stats().unwrap();
114114

115-
let heap_usage = after.physical_mem - before.physical_mem;
116-
let virtual_usage = after.virtual_mem - before.virtual_mem;
115+
let heap_usage = isize::try_from(after.physical_mem).expect("physical mem too large")
116+
- isize::try_from(before.physical_mem).expect("physical mem too large");
117+
let virtual_usage = isize::try_from(after.virtual_mem).expect("virtual mem too large")
118+
- isize::try_from(before.virtual_mem).expect("virtual mem too large");
117119

118120
assert!(result.is_ok(), "Should parse {fixture_name} successfully");
119121

@@ -158,8 +160,8 @@ fn benchmark_fixture(
158160
max_time_ms: max,
159161
std_dev_ms: std_dev,
160162
runs,
161-
heap_usage_bytes: Some(heap_usage),
162-
virtual_usage_bytes: Some(virtual_usage),
163+
heap_usage_bytes: Some(heap_usage.unsigned_abs()),
164+
virtual_usage_bytes: Some(virtual_usage.unsigned_abs()),
163165
time_per_kib_ms,
164166
mb_per_s,
165167
}
@@ -237,7 +239,10 @@ fn discover_all_fixture_names() -> Vec<String> {
237239
let entry = entry.ok()?;
238240
let path = entry.path();
239241
if path.extension()?.to_str()? == "lock" {
240-
path.file_name()?.to_str().map(|s| s.to_string())
242+
path
243+
.file_name()?
244+
.to_str()
245+
.map(std::string::ToString::to_string)
241246
} else {
242247
None
243248
}
@@ -347,15 +352,15 @@ fn main() {
347352
std::process::exit(1);
348353
}
349354
} else {
350-
eprintln!("Could not load baseline from {}", baseline_path);
355+
eprintln!("Could not load baseline from {baseline_path}");
351356
}
352357
}
353358

354359
if let Some(save_path) = &args.save_baseline {
355360
if let Err(err) = save_baseline(save_path, &results) {
356-
eprintln!("Failed to save baseline to {}: {}", save_path, err);
361+
eprintln!("Failed to save baseline to {save_path}: {err}");
357362
} else if args.verbose {
358-
println!("Saved baseline to {}", save_path);
363+
println!("Saved baseline to {save_path}");
359364
}
360365
}
361366
}

crates/berry-bench/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ repository.workspace = true
77
version.workspace = true
88

99
[dependencies]
10-
berry-core = { path = "../berry-core" }
11-
berry-test = { path = "../berry-test" }
12-
criterion = { version = "0.5", features = ["html_reports"] }
13-
memory-stats = "1.1"
10+
berry-core = { workspace = true }
11+
berry-test = { workspace = true }
12+
criterion = { workspace = true }
13+
memory-stats = { workspace = true }
1414

1515
[[bench]]
1616
harness = false
1717
name = "parser_benchmarks"
1818

1919
[dev-dependencies]
20-
criterion = { version = "0.5", features = ["html_reports"] }
20+
criterion = { workspace = true }

crates/berry-bench/benches/parser_benchmarks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn benchmark_all_fixtures(c: &mut Criterion) {
299299

300300
for fixture_name in fixtures {
301301
let fixture = load_fixture(&fixture_name);
302-
let label = format!("{}", fixture_name.replace('.', "_").replace('-', "_"));
302+
let label = fixture_name.replace(['.', '-'], "_").to_string();
303303
group.bench_function(label, |b| {
304304
b.iter(|| {
305305
let result = parse_lockfile(black_box(&fixture));

crates/berry-core/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ repository.workspace = true
88
version = "0.1.0"
99

1010
[dependencies]
11-
nom = "8.0.0"
12-
13-
[dev-dependencies]
14-
berry-test = { path = "../berry-test" }
11+
nom = { workspace = true }
1512

1613
[lints]
1714
workspace = true

crates/berry-core/src/ident.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ impl Range {
118118
Some("exec") => Protocol::Exec,
119119
Some("link") => Protocol::Link,
120120
Some(p) if p.starts_with("git") => Protocol::Git,
121-
Some(_) => Protocol::Unknown,
122-
None => Protocol::Unknown,
121+
Some(_) | None => Protocol::Unknown,
123122
}
124123
}
125124

@@ -177,11 +176,9 @@ impl Range {
177176
Protocol::Git => {
178177
// Return full URL including scheme (e.g., git+ssh://...), not just selector
179178
let raw = self.raw();
180-
if let Some(pos) = raw.find('#') {
179+
raw.find('#').map_or(Some((raw, None)), |pos| {
181180
Some((&raw[..pos], Some(&raw[pos + 1..])))
182-
} else {
183-
Some((raw, None))
184-
}
181+
})
185182
}
186183
_ => None,
187184
}
@@ -192,11 +189,9 @@ impl Range {
192189
match self.protocol() {
193190
Protocol::Patch => {
194191
let sel = self.selector();
195-
if let Some(pos) = sel.find('#') {
192+
sel.find('#').map_or(Some((sel, None)), |pos| {
196193
Some((&sel[..pos], Some(&sel[pos + 1..])))
197-
} else {
198-
Some((sel, None))
199-
}
194+
})
200195
}
201196
_ => None,
202197
}

crates/berry-core/src/lockfile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ mod tests_parse_r_c {
192192

193193
#[test]
194194
fn test_parse_top_level_constraints_block() {
195-
let input = r#"constraints:
195+
let input = r"constraints:
196196
react@^18: npm:^18.2.0
197-
"#;
197+
";
198198
let (rest, constraints) = parse_constraints(input).expect("parse constraints");
199199
assert!(rest.is_empty());
200200
assert_eq!(constraints.len(), 1);

0 commit comments

Comments
 (0)