Repository navigation
perf(ui): skip grapheme segmentation for fitting strings - #177478
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a9b327714c
ℹ️ 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".
| for (const label of ["Synthetic Viewer", "Café", "👩🏽💻"]) { | ||
| expect(takeGraphemes(label, 48)).toBe(label); | ||
| } | ||
| expect(segment).not.toHaveBeenCalled(); |
There was a problem hiding this comment.
Remove the Segmenter call-shape assertion
When this helper is refactored, spying on Intl.Segmenter.prototype.segment makes the test depend on the current implementation rather than the returned grapheme behavior, while also failing to prove that an alternative implementation avoids equivalent work. Keep the output-based Unicode cases and leave the zero-work evidence in the benchmark/PR; repository guidance requires independent unit contracts that prove the invariant rather than private call shape.
AGENTS.md reference: AGENTS.md:L78-L80
Useful? React with 👍 / 👎.
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
|
Codex review: needs changes before merge. What this changesSkip grapheme segmentation when a string’s UTF-16 length already fits the requested grapheme limit. Example: Generate an activity link for the label Synthetic Viewer with a 48-grapheme limit.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it removes measured UI work with a minimal, behavior-preserving change; the Segmenter spy needs a small test cleanup, and required CI remains blocked. Priority: P3 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe shared Control UI helper receives labels and numeric limits from activity routes, avatar initials, provider icons, plugin monograms, and question headers, returning text truncated at grapheme boundaries. flowchart TD
A[UI labels and limits] --> B[Shared grapheme helper]
B --> C[UTF-16 length check]
C --> D[Return fitting string]
C --> E[Existing grapheme segmentation]
D --> F[Routes and rendered text]
E --> F
Technical reviewBest possible solution: Keep the shared helper’s constant-time guard and existing Unicode loop, retain useful output cases, and remove the Segmenter spy. Do we have a high-confidence way to reproduce the issue? Current main visibly segments fitting labels, including activity-link labels limited to 48 graphemes; the PR supplies matching browser-profile evidence, but no target code was executed during this review. Is this the best way to solve the issue? The guard is the smallest complete production fix: grapheme count cannot exceed UTF-16 length, and inputs that might truncate still use the existing loop, including fractional, negative, and NaN limits. Full review comments:
Overall correctness: patch is correct AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a13e869e7d51. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +4, Tests +26. Total +30 across 2 files. Added test files: 1. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 19, 2026, 1:09 PM ET / 17:09 UTC. |
Related: #174756
What Problem This Solves
Short person labels were still segmented character by character when generating activity links during sidebar rendering and live updates.
User Impact
Less main-thread work for short labels. Truncation, Unicode grapheme boundaries, routes, and rendered text stay the same.
Why This Change Was Made
The source-mapped Team-scale profile identified
takeGraphemesas the largest application self-time on reload (63.944 ms). A grapheme occupies at least one UTF-16 code unit, so a string whose UTF-16 length already fits the requested grapheme limit needs no segmentation. Return it directly; retain the existing segmenter loop whenever truncation might be needed.This deletes work before considering caching. No cache, dependency, new owner, or lazy-boundary change is involved. Production LOC is 15 → 19 (+4) for the guard and its explanation. The direct test adds 26 lines and checks zero Segmenter calls for fitting labels plus Unicode and numeric-limit compatibility. All Solid refactor-checklist counts remain 0 → 0 in the touched production module.
Evidence
Acceptance rule, established before comparison: use the same committed Team-scale harness and fixed fixture on the same machine; preserve event/RPC counts and Unicode behavior; eliminate segmentation of fitting labels; compare five interleaved unprofiled samples per side, rejecting any unexplained ≥20% regression. Profile runs identify cost separately from unprofiled latency.
Workload: 390 fixture sessions, 240 transcript messages, 240 live session events over about 30.75 seconds. These are synthetic browser/Gateway fixtures, not a production Gateway measurement. The initial baseline sample did not record host load; subsequent pairs do.
takeGraphemesreload self/inclusiveactivityPersonLocationreload inclusivetakeGraphemeslive self/inclusiveThe 6-byte gzip increase buys the constant-time fast path; the strict startup check passes. No visible layout changed.
pnpm tsgo:uipnpm test ui/src/lib/graphemes.test.ts --maxWorkers=1pnpm deadcode:knipCommands:
node --import ./scripts/tsx.mjs scripts/bench-control-ui-cold-load.ts --live-events --session-event-churn --cpu-profile --untraced --runs 1 --fixture-now-ms 1792422000000; head additionally uses--cpu-profile-compare <baseline>/cpu-profile.json. Unprofiled runs reuse each built bundle with--bundle-dir, omit CPU profiling, and retain the other workload flags. Startup:pnpm ui:check-performance --dist <head>/ui --base-dist <base>/ui. Full UI CI is requested withci:fullbecause this helper has multiple UI consumers.Measured source heads: baseline
8b78b230a1c109fe6456964e59cb0eeefe63b7e5, candidatea9b327714c18d845e88a9971e3e364af0b1b28de.Unprofiled result
Overall timings are mixed; this PR claims the targeted CPU-work reduction, not a broad latency improvement. On the shared 32-CPU host, recorded one-minute load ranged from 41.5 to 67.5. Every sample is retained. p95 uses linear interpolation over five samples and is an estimate.
Each run retained 82 boot RPCs, 18 boot events, 240 live frames, zero live RPCs, and zero live long tasks. Reload long-task count median stayed 3; estimated p95 went 5.6 → 3.8. The untraced harness does not emit total reload CPU; profile CPU and wall-clock results are kept separate.
CI result and inherited-failure evidence
Run
39285492333passed all selected UI unit, UI E2E, performance, type, lint and security jobs. The real-Gateway job was not selected by this run, despiteci:full; no real-Gateway pass is claimed. The only root failure ischecks-fast-baseline-ratchets, reportingsrc/infra/openclaw-process-census.missing-command.test.ts:12: ./container-environment.js. The exact diagnostic reproduces from the complete CI base treed0e8fc8a103b2c37e98809ee46370748bb965155with the checker’s isolated-index--stagedmode. CI tested merge342199358a7e5e6d6e909749cbafed22bd8cb026has that base and this PR head as its ordered parents. Native inherited-failure recovery will verify complete CI/security accounting before landing; the failed gate remains recorded as failed.