Skip to content

perf(boards): avoid copying freshly decoded dashboard layouts - #184391

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-board-get-latency-20260919
Oct 26, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-board-get-latency-20260919

Conversation

@steipete

@steipete steipete commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Reading a populated session dashboard deep-clones the entire freshly decoded layout, including every plugin widget's props, before returning the snapshot.

User Impact

Dashboard snapshots require less CPU and allocation with identical payloads. This is a bounded improvement to populated board reads; it does not eliminate broader host or database-admission stalls affecting empty boards. No schema, configuration, authorization, or ordering changes.

Why This Change Was Made

The SQLite decoder already owns fresh tabs, widgets, and parsed props. Reuse the existing owned-layout normalizer there, while public operations continue copying caller-owned layouts. Copy only HTML declarations into view metadata to preserve isolation from the mutable snapshot. Production delta: +3 lines (one isolation comment/copy and formatting); no cache, second normalization algorithm, or new invalidation lifecycle.

Evidence

On current-main baseline d46ce5c, the strengthened existing store test fails specifically because it observes one full-layout copy. The candidate passes and also proves declaration isolation, subsequent-read isolation, and omission of HTML BLOBs.

Owner microbenchmark: 10,800 synthetic sessions, 24 native widgets with 120 structured data points each, 3,000 warmed reads per case. Timing and sampled-allocation passes are separate; payload hashes match.

Populated snapshot metric Before After
CPU/read 1.647 ms 0.608 ms
Sampled allocation/read 919,455 bytes 410,434 bytes
Wall p50 1.511 ms 0.537 ms
Wall p95 3.289 ms 0.967 ms

CPU fell 63.1% and sampled allocation 55.4% for this populated fixture. Empty reads remain about 0.04 ms p50 and 22 KiB/read. Host load was approximately 57–60 during the owner measurements; these are owner costs, not whole-Gateway CPU savings.

Real dist-Gateway phase proof uses isolated synthetic state, 10,800 sessions, 40 enabled bundled plugins, 65 authenticated WebSocket clients, and concurrent board/list requests. Baseline has 1,820 board calls: routing p50/p95 0.054/0.186 ms; reader retention 0.094/0.317 ms; read admission 106.634/231.013 ms; worker round trip 3.246/7.421 ms. No task, PR, GitHub, or Workboard service lookup occurs in board.get. Candidate has the same 1,820 board calls and matching wire-payload hash. Candidate phase p50/p95: routing 0.049/0.171 ms; reader retention 0.086/0.246 ms; admission 74.538/145.494 ms; worker round trip 1.977/4.034 ms. Server store-total p50/p95/p99: 109.672/236.934/322.603 → 76.540/148.622/184.344 ms (1,820 samples/arm). Client populated-board p50/p95: 136.581/313.829 → 102.000/198.307 ms (896 samples/arm); client list p50/p95: 23.604/53.259 → 21.572/47.784 ms (260 samples/arm). The untraced, instrumented burst completed in 7.80 → 5.18 s. Host one-minute load varied 55.1–58.4 on baseline and 50.2–54.9 on candidate; this short serial comparison supports phase attribution, not a production-wide tail claim or an adverse decision. Per-method client p99 has fewer than 1,000 samples and is not used as a gate.

The lane's explicit fast-path protocol applies: deletion of redundant recomputation with unchanged authority/FIFO, owner CPU+allocation measurement, targeted Gateway attribution, focused tests, CI, and independent review. No ten-minute AB/BA or A/A campaign and no live production load were run; whole-Gateway CPU/GC/allocation/loop effects are not claimed.

Validation: formatting and changed-file lint passed; 41 focused tests passed (board-store, board-layout, sqlite-board-codec; wrapper wall time 128.66 s including artifact preparation, board-store test body 26.9 s); export-name guard passed; 26 closure tests passed (69.91 s wall). The first CI run passed 54 checks but caught TS2638 in the clone-observation predicate; the test now narrows unknown values to non-null objects before using in. The failing tsconfig.core.test.other.json leaf, changed-file lint, and the targeted regression all pass locally (regression wrapper wall time 118.48 s including artifact preparation); fresh review found no issues. Corrected-head CI run 40294057978 is green; all 57 reported checks passed. The six changed-node test execution steps took 221/135/61/119/68/48 seconds (652 CI seconds total, including the dependency closure rather than only this regression). Initial test replay was invalidated by concurrent formatting and was rerun against frozen sources. Independent subagent review (autoreview route unavailable: configured provider mismatch) found no actionable P0–P2 findings. No Testbox lease was used, per lane instructions.

@clawsweeper

clawsweeper Bot commented Oct 26, 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.

@steipete
steipete marked this pull request as ready for review October 26, 2026 08:23
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T09:02:45.693415Z 05f8f3c New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
Reuse the owned layout normalizer after SQLite row decoding. Keep the HTML metadata declaration copy so snapshot mutations cannot affect view metadata, and retain full copies for caller-owned public operations. Removes a full-layout clone from every board snapshot read; preserves payloads, authorization and FIFO admission.
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR normalizes freshly decoded dashboard layouts without cloning them and preserves isolation between snapshots and HTML view metadata.

Example: Read a dashboard containing 24 plugin widgets with nested props.

  • Before: Every read deep-clones the freshly decoded widgets and props.
  • After: The decoder normalizes its owned objects directly while keeping HTML declarations separately copied.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The production change is focused and supported by reported Gateway measurements, but the new test contains a blocking type error.
Proof confidence 🐚 platinum hermit (4/6) The maintainer-authored PR is outside the contributor proof gate and reports populated board.get measurements through an isolated dist-Gateway, with matching payload hashes and separate CPU/allocation results.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Populated dashboard reads spend avoidable CPU and allocation copying objects that were freshly decoded.
Reason: The maintainer-authored direction is supported by bounded owner measurements and preserves payloads, public input isolation, storage format, and ordering.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this is a useful, focused allocation reduction, but the added clone-spy filter needs an object-type check before it can typecheck.

Priority: P2
Reviewed head: 485d74de945647468537e64eeb23f56c2e603d9d

Before merge

  • Narrow the clone argument to an object before using in (P2) - Vitest types these recorded arguments through Parameters<typeof structuredClone>, so value is unknown. The truthiness check narrows it to {}, which can still contain primitives and is not a valid right-hand operand for the in operator. Consequently the new regression test does not typecheck. Check typeof value === "object" and value !== null before testing "widgets" in value, without adding a cast or weakening the assertion.

Findings

  • [P2] Narrow the clone argument to an object before using in — src/boards/board-store.test.ts:264
Agent review details

How this fits together

The Board SQLite kernel decodes persisted tabs and widgets into snapshots consumed by dashboard RPCs and mutation operations.

flowchart LR
  A[Dashboard client] --> B[Board RPC]
  B --> C[Board storage worker]
  C --> D[SQLite row decoder]
  D --> E[Owned layout normalizer]
  E --> F[Snapshot and isolated metadata]
  F --> B
Loading

Technical review

Best possible solution:

Keep the production optimization and narrow the spy argument to a non-null object before checking for widgets.

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

Current-main source shows the redundant full-layout clone, and the added filter's type error follows from the inspected generic clone and spy contracts; no target code was executed.

Is this the best way to solve the issue?

Reusing the existing owned normalizer is the smallest complete production change because decoded objects are fresh and the separately copied declarations preserve the remaining sharing boundary.

Full review comments:

  • [P2] Narrow the clone argument to an object before using in — src/boards/board-store.test.ts:264
    Vitest types these recorded arguments through Parameters<typeof structuredClone>, so value is unknown. The truthiness check narrows it to {}, which can still contain primitives and is not a valid right-hand operand for the in operator. Consequently the new regression test does not typecheck. Check typeof value === "object" and value !== null before testing "widgets" in value, without adding a cast or weakening the assertion.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 977d7287c010.

Provenance checked

  • Layout normalization ownership keeps the original intent (3078402: Consolidate Board copying while preserving normal behavior and caller-owned input isolation; the subsequent array optimization retained that contract.)
  • HTML metadata projection keeps the original intent (428b5cc: Avoid HTML BLOB reads and repeated manifest parsing on board.get while retaining the metadata needed for widget views.)
  • SQLite Board kernel keeps the original intent (2330d13: Separate connection-bound operations from lifecycle ownership without changing schema, grants, revisions, or read ordering.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/boards/board-store.test.ts
  • node scripts/run-tsgo-core-test-shards.mjs --changed-paths-json '["src/boards/board-store.test.ts"]' --concurrency 2
  • pnpm exec oxfmt --check src/boards/board-store.test.ts
  • git diff --check

What I checked:

  • Introduced change and ownership boundary: The pinned diff replaces the decoder's copying normalization call with the existing owned normalizer, retains copying public operations, and copies HTML declarations to preserve independent consumers. (src/boards/sqlite-board-store.kernel.ts:100, 485d74de9456)
  • Current-main residual work: Fetched main still calls normalizeBoardLayout after constructing fresh decoded tabs and widgets, so this PR removes work that remains upstream. (src/boards/sqlite-board-store.kernel.ts:100, 977d7287c010)
  • Introduced test type error: The new filter applies the in operator to a generic clone argument after only truthiness narrowing; it needs an explicit object check. (src/boards/board-store.test.ts:264, 485d74de9456)
  • Spy argument type contract: The pinned Vitest release defines mock.calls through MockParameters<T>, which uses Parameters<T> for functions; extracting the generic structuredClone parameter yields unknown. (packages/spy/src/types.ts:43, 7a825db43e2b)
  • Generic clone declaration: The inspected Node declaration defines structuredClone as a generic function accepting T, supporting the unknown argument type obtained through Parameters. (types/node/web-globals/messaging.d.ts:10, 45aa16796155)
  • Exact-head CI limitation: The exact-head check-test-types-core-4 job failed during its typecheck step. Its annotation reports exit code 2, but the log download redirects to a blocked storage host, so the complete diagnostic and any additional failures remain unverified. (485d74de9456)

PR surface

Source +3, Tests +18. Total +21 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 12 9 +3
Tests 1 21 3 +18
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 33 12 +21

Labels

Label changes:

  • add P2: This is a bounded dashboard performance improvement with a narrow test-compilation defect and no demonstrated urgent runtime regression.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This is a bounded dashboard performance improvement with a narrow test-compilation defect and no demonstrated urgent runtime regression.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 26, 2026, 4:40 AM ET / 08:40 UTC.

@steipete
steipete force-pushed the steipete/perf-micro-board-get-latency-20260919 branch from 485d74d to 05f8f3c Compare October 26, 2026 08:41
@steipete
steipete merged commit d1a8e99 into main Oct 26, 2026
128 of 130 checks passed
@steipete
steipete deleted the steipete/perf-micro-board-get-latency-20260919 branch October 26, 2026 08:57
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…aw#184391)

* perf(boards): normalize freshly decoded snapshots without copying

Reuse the owned layout normalizer after SQLite row decoding. Keep the HTML metadata declaration copy so snapshot mutations cannot affect view metadata, and retain full copies for caller-owned public operations. Removes a full-layout clone from every board snapshot read; preserves payloads, authorization and FIFO admission.

* test(boards): narrow clone inputs before layout inspection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant