Skip to content

perf(plugin): Fix rust-skills CRITICAL and HIGH issues - #762

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

robcohen merged 2 commits into
mainfrom
fix-plugin-issues

Conversation

@robcohen

Copy link
Copy Markdown
Member

Summary

Fixes rust-skills violations in the plugin crate related to inline hints, memory allocation, and error handling.

Changes

File Change Impact
native/mod.rs:36 #[inline] on plugin_short_name() Performance for hot function
runtime.rs:266 Vec::with_capacity() Saves 1 alloc per execution
runtime.rs:364 Comment for unwrap_or_else Code clarity

Impact

  • Performance: Inline hint for frequently-called plugin name lookup
  • Memory: Reduces allocations during plugin execution
  • Clarity: Comments explain error handling rationale
  • Plugin crate compiles successfully ✅

rust-skills Rules Addressed

  • opt-inline-hints ✅ Fixed
  • mem-vec-with-capacity ✅ Fixed
  • err-no-unwrap-prod ✅ Documented

rust-skills: opt-inline-hints, mem-vec-with-capacity, err-no-unwrap-prod

Applied rust-skills review recommendations:

1. native/mod.rs:36 - Add #[inline] to plugin_short_name()
   - Hot function called during plugin lookup
   - Improves performance for frequent name matching

2. runtime.rs:266 - Vec::with_capacity(self.plugins.len())
   - Pre-allocate errors Vec in execute_all()
   - Saves 1 alloc per plugin execution batch

3. runtime.rs:364 - Add comment for unwrap_or_else
   - Clarifies why canonicalize failure is acceptable
   - Handles symlink issues gracefully

Tests: Plugin crate compiles successfully.
@robcohen
robcohen requested a review from a team as a code owner April 11, 2026 15:56
Copilot AI review requested due to automatic review settings April 11, 2026 15:56

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 aims to address rust-skills findings in the rustledger-plugin crate by adding an inline hint, reducing allocations during plugin execution, and clarifying an error-handling decision.

Changes:

  • Pre-allocate the all_errors vector in PluginManager::execute_all.
  • Add an inline hint to plugin_short_name in the native plugin registry.
  • Document why canonicalize() failures fall back to the original path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/rustledger-plugin/src/runtime.rs Adjusts allocation strategy for aggregated plugin errors and documents canonicalization fallback behavior.
crates/rustledger-plugin/src/native/mod.rs Adds an inline hint to a hot-path helper for native plugin name lookup.

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

Comment thread crates/rustledger-plugin/src/runtime.rs Resolved
@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!

@github-actions

github-actions Bot commented Apr 11, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 40.4ms ± 0.7ms 23.1 MB
beancount 753.8ms ± 5.3ms 50.1 MB
Comparison 18.7x faster 2.2x less

vs main branch (2026-04-11)

Metric main this PR Change
Time 41.9ms 40.4ms -3.6% ✅
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

`NativePluginRegistry::execute_all` was preallocating `all_errors`
with `Vec::with_capacity(self.plugins.len())` on every invocation,
which meant an unconditional heap allocation even in the common
no-errors path. Previously (`Vec::new()`), that path was zero-alloc.

Revert to `Vec::new()`. `Vec::new()` is free until the first push,
and the first `extend` from a non-empty `output.errors` pays for the
first grow then. For the typical "plugins ran clean" case this saves
one allocation per `execute_all` call.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@robcohen
robcohen enabled auto-merge April 11, 2026 16:34
@robcohen
robcohen added this pull request to the merge queue Apr 11, 2026
Merged via the queue into main with commit 7460f3e Apr 11, 2026
30 of 33 checks passed
@robcohen
robcohen deleted the fix-plugin-issues branch April 11, 2026 16:54
@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