perf(sdk): cache pricing snapshot, hoist regex statics, slim sum_costs alloc#388
perf(sdk): cache pricing snapshot, hoist regex statics, slim sum_costs alloc#388willwashburn wants to merge 1 commit intomainfrom
Conversation
…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().
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 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>, |
There was a problem hiding this comment.
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 👍 / 👎.
Closes #344.
Mechanical perf cleanups for the Rust analyze + reader hot paths called out in the May 2026 review.
Summary
analyze::pricing— parse the embeddedmodels.devJSON snapshot once into aLazyLock<PricingTable>.load_builtin_pricing()is invoked from at least five public verbs inquery_verbs.rs; it now clones the cached table instead of reparsing the snapshot on every call.analyze::ghost_surface—claude_command_name_re()becomes a module-scopestatic CLAUDE_COMMAND_NAME_RE: LazyLock<Regex>.analyze::claude_md—open_re/heading_relifted out offind_headingsintoOPEN_FENCE_RE/HEADING_RELazyLock<Regex>statics so the overhead loop reuses one compilation.reader::classifier— collapse the two duplicate^[A-Za-z_][A-Za-z0-9_]*=LazyLockcells inskip_env_assignmentsandenv_command_argsinto a single sharedENV_ASSIGN_REstatic.analyze::cost—CostBreakdown::modelis nowCow<'static, str>.sum_costscarries the"aggregate"label asCow::Borrowed(no allocation regardless of input length), while per-turn / per-label call sites still own theirStringviaCow::Owned/.into().Test plan
cargo build --workspacecargo test --workspace— 620 SDK unit tests + integration tests pass; including the existingsum_costs_*cases that pinmodel == "aggregate".Generated by Claude Code