Skip to content

perf(validate): Fix rust-skills CRITICAL issues - #759

Merged
robcohen merged 2 commits into
mainfrom
fix-validate-issues
Apr 11, 2026
Merged

robcohen merged 2 commits into
mainfrom
fix-validate-issues

Conversation

@robcohen

Copy link
Copy Markdown
Member

Summary

Fixes critical rust-skills violations in the validate crate related to memory allocation and error documentation.

Changes

File Change Impact
lib.rs:334 Vec::with_capacity(directives.len()) Saves 1 alloc per validation
balance.rs:77-84 Remove intermediate format!() Saves 1 alloc per balance error
error.rs:214-261 Add # Errors docs API documentation

Impact

  • Memory: Reduces allocations during validation
  • Documentation: Public API now has proper error documentation
  • All 26 tests pass ✅

rust-skills Rules Addressed

  • mem-vec-with-capacity ✅ Fixed
  • mem-avoid-format ✅ Fixed
  • err-doc-errors ✅ Fixed

rust-skills: mem-vec-with-capacity, err-doc-errors

Applied rust-skills review recommendations:

1. lib.rs:334 - Vec::with_capacity for sorted directives
   - Avoids intermediate collect() allocation
   - Saves 1 alloc per validation run

2. balance.rs:77-84 - Remove intermediate format!()
   - Direct collect + join instead of format! wrapper
   - Saves 1 alloc per balance validation error

3. error.rs:214-261 - Add # Errors docs
   - ValidationError::new, with_location, with_context
   - Improves API documentation

Tests: All 26 tests pass.
@robcohen
robcohen requested a review from a team as a code owner April 11, 2026 15:35
Copilot AI review requested due to automatic review settings April 11, 2026 15:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses rust-skills validation findings in rustledger-validate, focusing on reducing allocations during validation and improving public API documentation.

Changes:

  • Pre-allocates the directive reference vector before sorting to avoid potential reallocations.
  • Removes an intermediate format!() allocation when building balance-validation context.
  • Adds # Errors sections to ValidationError public method docs to satisfy documentation rules.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
crates/rustledger-validate/src/validators/balance.rs Adjusts how balance error context strings are constructed to avoid an extra format!() allocation.
crates/rustledger-validate/src/lib.rs Pre-allocates the sorted vector before extending it with directive references.
crates/rustledger-validate/src/error.rs Adds # Errors sections to ValidationError method documentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/rustledger-validate/src/error.rs Resolved
Comment thread crates/rustledger-validate/src/error.rs Resolved
Comment thread crates/rustledger-validate/src/error.rs Resolved
@github-actions

github-actions Bot commented Apr 11, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 40.3ms ± 0.3ms 23.2 MB
beancount 756.8ms ± 10.2ms 50.2 MB
Comparison 18.8x faster 2.2x less

vs main branch (2026-04-11)

Metric main this PR Change
Time 41.9ms 40.3ms -3.8% ✅
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

github-actions Bot commented Apr 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 99%
BQL Compatibility 100%
Full AST Match 98%
Total Files 784
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@codecov

codecov Bot commented Apr 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Four inline comments, all legitimate:

1. `validate_balance` lost the "pad dates: " prefix from the
   `with_context(...)` call on E2004 (multiple pad directives before a
   balance assertion). Without the prefix, the context string is just a
   comma-separated list of dates with no label, which is ambiguous to
   end users. Restored the original "pad dates: {}" wrapping.

2-4. `ValidationError::{new, with_location, with_context}` had `# Errors`
   doc sections added, but none of these constructors are fallible
   (they all return `Self`, not `Result`). The workspace clippy config
   has `missing_errors_doc = "allow"`, so the sections were not
   satisfying any required lint and were actively misleading the
   reader. Removed all three.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@robcohen
robcohen enabled auto-merge April 11, 2026 16:19
@robcohen
robcohen added this pull request to the merge queue Apr 11, 2026
Merged via the queue into main with commit 7c10c33 Apr 11, 2026
31 of 34 checks passed
@robcohen
robcohen deleted the fix-validate-issues branch April 11, 2026 16:33
@rustledger-bot rustledger-bot Bot mentioned this pull request Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants