Skip to content

improve(ui): render provider usage histories with less repeated work - #141194

Merged
steipete merged 1 commit into
mainfrom
codex/perf55-provider-usage-render
Sep 7, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf55-provider-usage-render

Conversation

@steipete

@steipete steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Provider usage cards do repeated formatting and history scans whenever the Usage dashboard or Models settings renders. A 30-day history constructs currency formatters for every displayed value, including the same chart label twice.

Why This Change Was Made

Prepare one amount formatter for each billing row or nonempty history, reuse each chart label, and collect history totals and maximum in one pass. Keep this preparation local to the render so refreshed values and locale settings remain current. There is no cross-render cache.

Preserve raw unknown-unit spacing, JPY rounding, first-three attribution order, NaN/signed-zero behavior, left-to-right token summation and the two independent UTC date reads. Detailed history tests now live beside the shared component; Usage retains caller-level billing and visibility coverage. Production grows by one line; tests grow by 93 lines. No configuration, dependency, style, persistence or API changes.

User Impact

The same provider usage details render with less repeated work on both pages. In the fixed local comparison, creating a new 30-day history DOM is 36–40% faster; updating an existing one is about 89–90% faster. These are Lit/jsdom composition measurements, not browser paint/FPS, network or Gateway latency claims.

Evidence

All 136 tests across four complete component/page/format suites and all 20 selected normal checks passed. Independent P0–P2 review found no actionable findings. A separate audit reconciled complete numeric and browser outcomes.

Numeric proof uses the actual shared renderer plus Lit commit in jsdom, including new containers, unchanged renders, same-object mutation, replacement data, same-container reattachment, supported/raw currencies, multiple providers, billing-only and error controls. Fixed B0/C0/C1/B1 order retains 1,356 whole render operations (1,444 provider-detail invocations): 960 steady measurements, 240 warmups, 100 seeds and 56 literal control executions. Every corresponding full DOM surface matches, including attributes and text; all independent currency/arithmetic/date controls pass.

All paired medians below show percentage reduction and candidate-minus-baseline microseconds. Negative reduction means slower.

Workload Forward reduction / Δµs Reverse reduction / Δµs
0-fresh +11.20% / -16.792 +3.33% / -4.542
0-unchanged +10.12% / -0.146 -6.15% / +0.082
0-mutated +7.55% / -2.688 -3.82% / +1.313
0-replacement -12.47% / +2.500 +1.35% / -0.271
0-remount +3.02% / -0.042 -32.24% / +0.417
1-fresh +9.11% / -80.980 +10.15% / -97.313
1-unchanged +48.29% / -72.771 +48.18% / -71.542
1-mutated +43.15% / -68.167 +43.19% / -67.875
1-replacement +47.24% / -73.562 +50.12% / -73.042
1-remount +55.83% / -80.126 +56.74% / -81.500
7-fresh +27.61% / -312.083 +10.69% / -110.978
7-unchanged +76.07% / -233.208 +74.67% / -225.979
7-mutated +64.67% / -224.126 +65.35% / -209.146
7-replacement +69.41% / -227.729 +66.40% / -211.938
7-remount +75.38% / -223.000 +75.43% / -233.667
30-fresh +39.51% / -797.687 +36.32% / -756.770
30-unchanged +89.18% / -842.500 +90.11% / -862.917
30-mutated +86.56% / -796.416 +89.99% / -905.855
30-replacement +89.20% / -850.605 +88.65% / -902.104
30-remount +90.70% / -840.208 +89.92% / -835.979
90-fresh +51.35% / -2654.208 +47.03% / -2424.749
90-unchanged +94.80% / -2467.437 +94.95% / -2491.104
90-mutated +93.78% / -2476.729 +93.54% / -2491.833
90-replacement +95.03% / -2599.208 +93.97% / -2545.958
90-remount +94.75% / -2411.876 +94.94% / -2490.313
jpy-30 +91.42% / -841.792 +91.37% / -826.166
raw-30 +89.36% / -648.479 +90.17% / -649.938
multi-30 +91.00% / -2395.146 +90.16% / -2427.313
billing-only +5.71% / -4.437 +8.44% / -6.562
error-90 +16.96% / -3.438 +8.24% / -1.458

Fifty-six of 60 medians improve. All 19 adverse metrics out of 240 are retained: four medians, six means, two minima and seven maxima. The four adverse medians are empty-history controls; the largest absolute increase is 2.50 µs. Eight steady calls per row/process and one fixed cohort do not establish stable tail behavior. Same-container reattachment retains Lit’s existing root; it is not a fresh component lifetime.

Whole-process wall time falls 19.08%/19.89%; all ten retained CPU/RSS/wall comparisons improve, but these include imports, setup and capture and do not establish a general memory benefit. The full raw outputs, complete clock traces, every timing sample and resource observation remain retained.

Real Chromium with the repository’s source-server/mock-Gateway harness passed all 16 states: both actual pages, before and after Refresh, on baseline and candidate, with en-US and de-DE number formatting. Eight Refresh actions each produced a new usage.status request; no config.patch occurred. Full provider-card DOM matches across variants, and shared detail DOM matches between pages. All browser/process owners closed and candidate source was restored. This is browser integration proof with synthetic data, not an authenticated live provider test.

Two failed proof setups remain preserved separately: the first numeric baseline warmup incorrectly counted jsdom’s inert-document Date read as a provider clock; the first browser baseline reached seven states before its English Refresh selector met a legitimately German UI. The corrected observer retains provider/framework clock calls separately inside the same full-render timer; the corrected browser fixture uses the existing explicit server UI-language preference while leaving Intl locale varied. No production change, relaxed assertion, increased timeout or favorable timing rerun was used to resolve either issue.

Synthetic before/after captures below show unchanged presentation for Usage and refreshed Models details. They contain no real account data or credentials.

Before: Usage history with synthetic data

After: Same Usage history with synthetic data

Before: Refreshed Models history with German number formatting

After: Same refreshed Models history with German number formatting

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: M maintainer Maintainer-authored PR labels Sep 7, 2026
@steipete
steipete marked this pull request as ready for review September 7, 2026 11:54
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 8:01 AM ET / 12:01 UTC.

ClawSweeper review

What this changes

The PR reduces repeated currency formatting and history aggregation in provider usage cards while preserving their displayed values and moving detailed coverage beside the shared renderer.

Merge readiness

✅ Ready for maintainer review

Keep open: this is a useful, bounded optimization absent from inspected main and the latest release. No actionable correctness defect was found, and the maintainer-authored PR is protected from cleanup closure.

Priority: P3
Reviewed head: 4143fffb6927d714d984d0bf95b9a1c96fe87ca3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving optimization with useful boundary coverage and carefully scoped performance claims.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor-proof gate is exempt for this maintainer-authored PR. Supplemental evidence reports the actual shared renderer in Chromium on Usage and Models, refreshed values and locale parity, plus composition timings; screenshots could not be retrieved independently.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor-proof gate is exempt for this maintainer-authored PR. Supplemental evidence reports the actual shared renderer in Chromium on Usage and Models, refreshed values and locale parity, plus composition timings; screenshots could not be retrieved independently.
Evidence reviewed 6 items Introduced production change: The verified merge-base-to-head diff changes only render-local preparation: formatter options, raw-unit spacing, arithmetic order, UTC window calculations, and attribution ordering remain equivalent.
Still useful on main: Inspected main still constructs a formatter for each amount, formats each chart label twice, and separately computes maxima, token totals, and period totals.
Latest release comparison: The supplied latest release also retains the repeated formatting and separate history reductions; this optimization is not already present there.
Findings None None.
Security None None.

How this fits together

The Control UI receives provider-reported usage snapshots from the Gateway. A shared renderer turns those snapshots into billing totals, daily charts, and attribution details on the Usage and Models pages.

flowchart LR
  A[Gateway usage snapshots] --> B[Usage and Models pages]
  B --> C{Provider error?}
  C -->|Yes| D[Error message]
  C -->|No| E[Prepare formatter and totals]
  E --> F[Billing and history cards]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1, Tests +93. Total +94 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 27 26 +1
Tests 2 163 70 +93
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 190 96 +94

Review metrics

Metric Value Why it matters
History currency formatter construction 63–66 instances reduced to 1 for a 30-day history The shared renderer previously constructed one formatter for each window, both labels on every daily bar, and up to three categories.

Technical review

Best possible solution:

Keep formatting and aggregation local to each shared render so both pages benefit without stale values or locale state.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a functional bug report; repeated formatter construction and history scans are directly visible in main, and the supplied comparison measures their cost.

Is this the best way to solve the issue?

Yes. Reusing preparation within the existing renderer removes repeated work without adding persistent caching, competing APIs, or changed formatting semantics.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 01e307c2c295.

Labels

Label changes:

  • add P3: This is a bounded rendering-efficiency improvement with unchanged user-facing behavior.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor-proof gate is exempt for this maintainer-authored PR. Supplemental evidence reports the actual shared renderer in Chromium on Usage and Models, refreshed values and locale parity, plus composition timings; screenshots could not be retrieved independently.

Label justifications:

  • P3: This is a bounded rendering-efficiency improvement with unchanged user-facing behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor-proof gate is exempt for this maintainer-authored PR. Supplemental evidence reports the actual shared renderer in Chromium on Usage and Models, refreshed values and locale parity, plus composition timings; screenshots could not be retrieved independently.

Evidence

What I checked:

  • Introduced production change: The verified merge-base-to-head diff changes only render-local preparation: formatter options, raw-unit spacing, arithmetic order, UTC window calculations, and attribution ordering remain equivalent. (ui/src/components/provider-usage.ts:10, 4143fffb6927)
  • Still useful on main: Inspected main still constructs a formatter for each amount, formats each chart label twice, and separately computes maxima, token totals, and period totals. (ui/src/components/provider-usage.ts:10, 01e307c2c295)
  • Latest release comparison: The supplied latest release also retains the repeated formatting and separate history reductions; this optimization is not already present there. (ui/src/components/provider-usage.ts:10, 3928bad9badf)
  • Shared owner and preserved coverage: Both page callers invoke the same renderer. The new component tests cover currency normalization, raw units, chart accessibility labels, nonfinite values, signed zero, source-order arithmetic, and input immutability; Usage retains caller-level billing coverage. Tests were inspected, not executed. (ui/src/components/provider-usage.test.ts:7, 4143fffb6927)
  • Supplied performance and browser evidence: The complete captured PR body reports paired Lit/jsdom measurements and Chromium coverage of both actual pages before/after Refresh in two number locales, with matching DOM and eight new usage.status requests. It explicitly limits performance claims to composition time. Linked screenshot retrieval failed in this review environment, so the images were not independently inspected. Captured context identity: 29260fd361bd96eefdb7c94865fa6da3524bace080fc3616134e4a44f0ff5a7b. (4143fffb6927)
  • Area-history routing: Available main history records Peter Steinberger on the shared renderer's Models-page work, token-format consolidation, and error redaction. Deeper line attribution could not complete because historical objects were unavailable; no introduction claim is made. (ui/src/components/provider-usage.ts, 007400568221)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 2ddfd93 into main Sep 7, 2026
182 checks passed
@steipete
steipete deleted the codex/perf55-provider-usage-render branch September 7, 2026 12:52
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant