Skip to content

perf(sdk): cache pricing snapshot, hoist regex statics, slim sum_costs alloc#388

Open
willwashburn wants to merge 1 commit intomainfrom
claude/fix-issue-344-RJ08x
Open

perf(sdk): cache pricing snapshot, hoist regex statics, slim sum_costs alloc#388
willwashburn wants to merge 1 commit intomainfrom
claude/fix-issue-344-RJ08x

Conversation

@willwashburn
Copy link
Copy Markdown
Member

Closes #344.

Mechanical perf cleanups for the Rust analyze + reader hot paths called out in the May 2026 review.

Summary

  • analyze::pricing — parse the embedded models.dev JSON snapshot once into a LazyLock<PricingTable>. load_builtin_pricing() is invoked from at least five public verbs in query_verbs.rs; it now clones the cached table instead of reparsing the snapshot on every call.
  • analyze::ghost_surfaceclaude_command_name_re() becomes a module-scope static CLAUDE_COMMAND_NAME_RE: LazyLock<Regex>.
  • analyze::claude_mdopen_re / heading_re lifted out of find_headings into OPEN_FENCE_RE / HEADING_RE LazyLock<Regex> statics so the overhead loop reuses one compilation.
  • reader::classifier — collapse the two duplicate ^[A-Za-z_][A-Za-z0-9_]*= LazyLock cells in skip_env_assignments and env_command_args into a single shared ENV_ASSIGN_RE static.
  • analyze::costCostBreakdown::model is now Cow<'static, str>. sum_costs carries the "aggregate" label as Cow::Borrowed (no allocation regardless of input length), while per-turn / per-label call sites still own their String via Cow::Owned / .into().

Test plan

  • cargo build --workspace
  • cargo test --workspace — 620 SDK unit tests + integration tests pass; including the existing sum_costs_* cases that pin model == "aggregate".
  • CI conformance gate stays green.

Generated by Claude Code

…s alloc (#344)

- analyze::pricing: parse the embedded models.dev snapshot once into a
  LazyLock<PricingTable> so load_builtin_pricing only clones the cached
  table instead of re-parsing on every public verb call.
- analyze::ghost_surface, analyze::claude_md: hoist per-call Regex builders
  to module-scope LazyLock statics so claude_command_name_re / open-fence /
  heading regexes compile exactly once.
- reader::classifier: collapse the two duplicate `KEY=` LazyLock cells in
  skip_env_assignments and env_command_args into a single shared
  ENV_ASSIGN_RE static.
- analyze::cost: switch CostBreakdown::model to Cow<'static, str> so
  sum_costs carries the "aggregate" label as a 'static borrow without
  allocating, while per-turn breakdowns and dynamic labels keep their
  owned String via Cow::Owned / .into().
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Warning

Rate limit exceeded

@willwashburn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minute and 46 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7e85b61b-7af3-44b6-b33d-8b1d8de375a4

📥 Commits

Reviewing files that changed from the base of the PR and between 0f2dc86 and fbe332e.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • crates/relayburn-cli/src/commands/summary.rs
  • crates/relayburn-sdk/src/analyze/claude_md.rs
  • crates/relayburn-sdk/src/analyze/cost.rs
  • crates/relayburn-sdk/src/analyze/ghost_surface.rs
  • crates/relayburn-sdk/src/analyze/pricing.rs
  • crates/relayburn-sdk/src/analyze/provider.rs
  • crates/relayburn-sdk/src/reader/classifier.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/fix-issue-344-RJ08x

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fbe332e361

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

/// `Cow<'static, str>` so common labels like `"aggregate"` (from
/// [`sum_costs`]) can be carried as a `'static` borrow with no allocation,
/// while per-turn breakdowns can still own a `String`.
pub model: Cow<'static, str>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve CostBreakdown::model as String in public SDK API

Changing CostBreakdown::model from String to Cow<'static, str> introduces a source-breaking change for downstream relayburn-sdk consumers: external code that constructs CostBreakdown via struct literals with String values (or otherwise relies on the field’s concrete String type) will fail to compile after upgrade. Since this commit is a perf refactor in a published crate, the type change should be avoided (optimize internally instead) or shipped only as an explicit major-version API break.

Useful? React with 👍 / 👎.

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.

Rust perf: cache LazyLock pricing table; hoist regex statics

2 participants