Skip to content

perf(Text): a truncation measurement that finds the same result sets no state - #11911

Merged
cixzhang merged 2 commits into
mainfrom
l0/text-truncation-no-op-dispatch
Nov 17, 2026
Merged

cixzhang merged 2 commits into
mainfrom
l0/text-truncation-no-op-dispatch

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

User impact

  • Who: pages that mount many truncating texts at once, such as a wide Table that windows its columns (each default cell renders <Text maxLines={1}>).
  • Before: every measurement that useTruncation ran set its isTruncated and fullText state, even when the values were unchanged. A Table column range step dispatched about 119 such updates (real-Chrome stack probe on a 1,000-column table), including updates on the cells being removed.
  • After: a measurement that finds the same values dispatches nothing. useTruncation's public return is identical: isTruncated and fullText hold exactly the values they held before, at the same times. Only no-op dispatches go away.

What changed

  • Text/useTruncation.ts: the hook keeps the values it last set as state in a ref, and its two setters skip the dispatch when the new value equals that one. Every call site keeps its value and timing.
  • [perf] changeset.

Evidence

  • First-load size (architecture:component-import-boundaries INV10; useTruncation.ts is shared by Text, Heading, Lightbox and Lab's LineClamp), pnpm size:pages from the merge base 344ec5b, gzip: docs +30 B, form +42 B, menu +32 B, table +43 B, each inside INV10's 0.3 KB allowance.
  • Consumer suites pass: Text (including useTruncation.test.tsx), Heading, Lightbox, Table, Lab LineClamp, and the CLI's use-truncation-hook-usage template test (61 files, 1,476 tests). tsc and eslint are clean.
  • Real-Chrome evidence (jsdom's React drops a same-value update before it renders, so a jsdom render or commit count cannot see these dispatches). A stack probe on a 1,000-column windowed Table (Chrome 149, 300 range steps) counted Text truncation setStates per range step:
Build setStates per range step
Column windowing alone (#11844) 118.93
With this pull request (and #11893) 39.73

The remaining ~40 are real value changes: each newly mounted cell's first fullText, and the reset when a cell's element detaches. Both are kept, so the hook's output is unchanged.

Host Range p95, main Range p95, all four No-op p95, all four
First farm host 6.49–6.67 ms 3.43–3.50 ms 0.62–0.68 ms
Second farm host (about 18% slower) 7.59–8.03 ms 3.60–4.14 ms 0.72–0.99 ms
Release check's runner (4-core-ubuntu, timing gate on) — range-plus-commit p95 3.5 ms 0.1 ms

On both farm hosts the range step costs about half of main's, with one commit per range step (main: 3). On the release check's runner, which decides PR3, the four together meet it: range-plus-commit p95 3.5 ms (≤ 4) and no-op p95 0.1 ms (≤ 2), measured with the Table release proof's own scroll-to-commit probe in one gated run. The last of the four to land claims PR3.

Scope

  • One hook file; no API, record or output change.
  • Public text contains no internal context.

Overlap checked: #11105 (it moves Text and Heading toward server rendering and touches useTruncation.ts for that; this changes only when the hook's setters dispatch)

Owner: Astryx fix-loop lane 0. Land path: CodeBunny approval of the exact head, Specs stamp, CI, then the merge queue.

…no state

useTruncation set isTruncated and fullText on every measurement, even
when the values were unchanged, so a list that mounts many texts
dispatched many updates that changed nothing. Its setters now skip the
dispatch when the value equals the one last set. The hook returns the
same values at the same times.
@vercel

vercel Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 16, 2026 3:08am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 15, 2026
@astracat-bot

astracat-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🔄 In progress (for maintainers only) Nov 17, 2026, 5:40 PM UTC

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec ecb513f

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 6fc52db

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
lab/TabBarMoreList 102.0 kB (+68 B) · 1.8 kB CSS (0) — — · — · —
Timer 13.1 kB (+67 B) · 6.1 kB CSS (0) — — · — · —
Selector 112.8 kB (+65 B) · 18.6 kB CSS (0) — — · — · —
99 more components
Component Size LoC Visual · A11y · RTL
Field 59.5 kB (+64 B) · 7.3 kB CSS (0) — — · — · —
lab/Schedule 114.7 kB (+62 B) · 3.9 kB CSS (0) — — · — · —
ComplexSelector 77.6 kB (+60 B) · 12.6 kB CSS (0) — — · — · —
TextInput 72.8 kB (+60 B) · 12.0 kB CSS (0) — — · — · —
Markdown 202.7 kB (+59 B) · 21.9 kB CSS (0) — — · — · —
Switch 109.0 kB (+57 B) · 10.0 kB CSS (0) — — · — · —
Calendar 76.1 kB (+54 B) · 11.4 kB CSS (0) — — · — · —
InputGroup 61.1 kB (+54 B) · 7.9 kB CSS (0) — — · — · —
Pagination 123.8 kB (+54 B) · 19.0 kB CSS (0) — — · — · —
lab/SelectableCardGroup 68.8 kB (+54 B) · 162 B CSS (0) — — · — · —
ChatLayout 88.3 kB (+53 B) · 11.3 kB CSS (0) — — · — · —
MultiSelector 101.5 kB (+53 B) · 17.7 kB CSS (0) — — · — · —
Slider 114.5 kB (+53 B) · 8.9 kB CSS (0) — — · — · —
RadioListItem 76.1 kB (+52 B) · 10.7 kB CSS (0) — — · — · —
ToggleButton 92.1 kB (+52 B) · 10.9 kB CSS (0) — — · — · —
AlertDialog 128.7 kB (+51 B) · 15.4 kB CSS (0) — — · — · —
CheckboxList 73.2 kB (+51 B) · 7.8 kB CSS (0) — — · — · —
richtext/RichTextView 282.2 kB (+51 B) · 2.3 kB CSS (0) — — · — · —
RadioList 60.8 kB (+50 B) · 7.3 kB CSS (0) — — · — · —
Text · Storybook 11.0 kB (+50 B) · 5.5 kB CSS (0) 753 (+13) ✓ · ✓ · —
CommandPaletteInput 33.0 kB (+49 B) · 7.6 kB CSS (0) — — · — · —
FileInput 74.2 kB (+49 B) · 11.7 kB CSS (0) — — · — · —
CheckboxListItem 79.9 kB (+48 B) · 12.0 kB CSS (0) — — · — · —
DateRangeInput 99.3 kB (+48 B) · 13.3 kB CSS (0) — — · — · —
DropdownMenu 107.4 kB (+48 B) · 18.8 kB CSS (0) — — · — · —
DropdownMenuSubMenu 78.5 kB (+48 B) · 10.4 kB CSS (0) — — · — · —
ListItem 79.1 kB (+48 B) · 12.0 kB CSS (0) — — · — · —
MobileNav 76.3 kB (+48 B) · 11.4 kB CSS (0) — — · — · —
SideNavCollapseButton 65.9 kB (+48 B) · 10.8 kB CSS (0) — — · — · —
TextArea 66.9 kB (+48 B) · 9.4 kB CSS (0) — — · — · —
lab/LineClamp 13.5 kB (+48 B) · 168 B CSS (0) — — · — · —
ChatToolCalls 31.6 kB (+47 B) · 8.4 kB CSS (0) — — · — · —
MoreMenu 107.6 kB (+47 B) · 18.8 kB CSS (0) — — · — · —
Spinner 24.0 kB (+47 B) · 6.3 kB CSS (0) — — · — · —
Table 120.2 kB (+47 B) · 19.6 kB CSS (0) — — · — · —
Tokenizer 104.3 kB (+47 B) · 20.3 kB CSS (0) — — · — · —
lab/EmojiPicker 92.5 kB (+47 B) · 751 B CSS (0) — — · — · —
richtext/RichTextEditorToolbar 299.6 kB (+47 B) · 454 B CSS (0) — — · — · —
CheckboxInput 69.0 kB (+46 B) · 10.1 kB CSS (0) — — · — · —
AppShell 97.6 kB (+45 B) · 14.3 kB CSS (0) — — · — · —
DialogHeader 67.9 kB (+45 B) · 12.3 kB CSS (0) — — · — · —
lab/DialogHeroHeader 88.6 kB (+45 B) · 372 B CSS (0) — — · — · —
ChatMessageList 27.4 kB (+44 B) · 7.1 kB CSS (0) — — · — · —
DateTimeInput 223.5 kB (+44 B) · 19.7 kB CSS (0) — — · — · —
DrawerHeader 68.0 kB (+44 B) · 13.7 kB CSS (0) — — · — · —
NumberInput 77.6 kB (+44 B) · 12.2 kB CSS (0) — — · — · —
Popover 98.6 kB (+44 B) · 15.1 kB CSS (0) — — · — · —
SideNav 121.2 kB (+44 B) · 12.2 kB CSS (0) — — · — · —
TopNav 78.0 kB (+44 B) · 11.7 kB CSS (0) — — · — · —
CodeBlock 80.1 kB (+43 B) · 12.1 kB CSS (0) — — · — · —
SideNavItem 77.0 kB (+42 B) · 11.9 kB CSS (0) — — · — · —
TableCell 103.3 kB (+42 B) · 19.1 kB CSS (0) — — · — · —
TableHeaderCell 103.0 kB (+42 B) · 18.9 kB CSS (0) — — · — · —
TabMenu 78.9 kB (+42 B) · 11.9 kB CSS (0) — — · — · —
ContextMenu 102.1 kB (+41 B) · 18.7 kB CSS (0) — — · — · —
DateInput 200.0 kB (+41 B) · 17.9 kB CSS (0) — — · — · —
Link 56.4 kB (+41 B) · 7.1 kB CSS (0) — — · — · —
PowerSearch 306.8 kB (+41 B) · 25.5 kB CSS (0) — — · — · —
Timestamp 27.0 kB (+41 B) · 11.0 kB CSS (0) — — · — · —
lab/Comments 369.8 kB (+41 B) · 2.5 kB CSS (0) — — · — · —
charts/ChartLegend 40.2 kB (+40 B) · 224 B CSS (0) — — · — · —
Carousel 74.7 kB (+40 B) · 11.7 kB CSS (0) — — · — · —
lab/ChatEmojiPicker 113.6 kB (+40 B) · 773 B CSS (0) — — · — · —
lab/CommentComposer 173.6 kB (+40 B) · 1.9 kB CSS (0) — — · — · —
lab/DiffViewer 93.2 kB (+40 B) · 2.1 kB CSS (0) — — · — · —
ChatLayoutScrollButton 65.6 kB (+39 B) · 11.0 kB CSS (0) — — · — · —
CommandPalette 77.8 kB (+39 B) · 12.7 kB CSS (0) — — · — · —
SideNavHeading 82.5 kB (+39 B) · 12.1 kB CSS (0) — — · — · —
Toast 103.6 kB (+39 B) · 11.1 kB CSS (0) — — · — · —
lab/ListInput 93.6 kB (+39 B) · 922 B CSS (0) — — · — · —
TopNavMegaMenu 76.1 kB (+38 B) · 12.6 kB CSS (0) — — · — · —
lab/ChatReactionBar 114.8 kB (+38 B) · 1.1 kB CSS (0) — — · — · —
lab/CommentThread 362.9 kB (+38 B) · 2.4 kB CSS (0) — — · — · —
lab/TourStep 93.2 kB (+38 B) · 691 B CSS (0) — — · — · —
richtext/RichTextEditor 305.6 kB (+38 B) · 2.6 kB CSS (0) — — · — · —
Stepper 66.7 kB (+37 B) · 10.9 kB CSS (0) — — · — · —
TimeInput 174.8 kB (+37 B) · 16.9 kB CSS (0) — — · — · —
TopNavMenu 81.6 kB (+37 B) · 12.0 kB CSS (0) — — · — · —
ChatDictationButton 65.6 kB (+36 B) · 10.8 kB CSS (0) — — · — · —
ChatSendButton 65.4 kB (+36 B) · 10.8 kB CSS (0) — — · — · —
Heading 11.6 kB (+36 B) · 5.5 kB CSS (0) — — · — · —
Banner 67.0 kB (+35 B) · 11.3 kB CSS (0) — — · — · —
ChatComposer 84.6 kB (+35 B) · 12.9 kB CSS (0) — — · — · —
Thumbnail 69.4 kB (+35 B) · 12.3 kB CSS (0) — — · — · —
IconButton 65.0 kB (+34 B) · 10.8 kB CSS (0) — — · — · —
Typeahead 87.9 kB (+34 B) · 13.5 kB CSS (0) — — · — · —
TopNavHeading 82.1 kB (+33 B) · 12.0 kB CSS (0) — — · — · —
Lightbox 145.9 kB (+32 B) · 11.9 kB CSS (0) — — · — · —
TableSelectionToolbar 75.3 kB (+32 B) · 14.0 kB CSS (0) — — · — · —
Button 65.0 kB (+31 B) · 10.8 kB CSS (0) — — · — · —
MobileNavToggle 65.3 kB (+31 B) · 10.8 kB CSS (0) — — · — · —
lab/TransferListSelector 121.1 kB (+31 B) · 1.4 kB CSS (0) — — · — · —
BaseTypeahead 78.4 kB (+30 B) · 11.7 kB CSS (0) — — · — · —
ChatComposerInput 82.2 kB (+26 B) · 12.1 kB CSS (0) — — · — · —
ChatComposerTokenElement 82.2 kB (+26 B) · 12.1 kB CSS (0) — — · — · —
lab/TransferList 112.2 kB (+26 B) · 1.2 kB CSS (0) — — · — · —
BreadcrumbItem 96.9 kB (+25 B) · 13.3 kB CSS (0) — — · — · —
charts/ChartTooltip 215.0 kB (+17 B) · 451 B CSS (0) — — · — · —
charts/Chart 237.9 kB (+15 B) · 516 B CSS (0) — — · — · —

Package size: @astryxdesign/core 7.61 MB packed (+365 B); no new dependencies.

Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes — one reporting gap; the code itself is clean, and the hook's returned values match main at every step this review probed.

  • packages/core/src/Text/useTruncation.ts is imported by the Text, Heading and Lightbox folders and by Lab's LineClamp, so it is a shared module, and this head grows it (its built output rises from 1,978 to 2,133 B gzip); architecture:component-import-boundaries INV10 asks a pull request that grows a shared module to report the first-load gzip delta on the four reference pages, and the description reports none. Measured here with pnpm size:pages over both trees' Core builds: docs +15 B, form +14 B, menu +28 B, table +9 B gzip, every page well inside INV10's 0.3 KB allowance — pasting those four numbers into the Evidence section clears this.

Two non-blocking notes: the release note opens [fix] while the change is a performance change with identical returned values, so [perf], which the repository already uses for this kind of note, would file it under Performance in the changelog; and packages/core/src/hooks/useScrollableArea.ts already holds a private setIfChanged with the same body, so the two copies can drift. Required CI has not run on this head yet, so the merge guard still needs it green.

Claims and files checked

Review mode: full; reason: no-earlier-review

Claims:

  • Pages that mount many truncating texts are affected, such as a wide Table whose default cell renders clamped Text — verified (packages/core/src/Table/BaseTable.tsx:277).
  • Before the change every measurement set both values even when unchanged — verified (the base hook calls both setters unconditionally).
  • About 119 such updates per Table column-range step, from a real-Chrome stack probe — unverified: that harness is outside this pull request and this review has no real browser; the description says the results land before the pull request leaves draft.
  • After the change a measurement that finds the same values dispatches nothing — verified (a re-measurement of the same text drops from 2 dispatches to 0).
  • The hook's public return is identical, at the same times — verified (base-against-head probe over mount, growth past the box, expand, collapse, element swap and a short text, in StrictMode and outside it).
  • The hook keeps the last values in a ref and both setters skip the equal dispatch, with every call site unchanged — verified (packages/core/src/Text/useTruncation.ts:79-96, :141, :200).
  • A [fix] changeset is included — verified; its category is the note above.
  • Consumer suites pass (Text, Heading, Lightbox, Table, Lab LineClamp and the CLI's truncation-hook template test; 61 files, 1,476 tests) and typecheck and lint are clean — verified (60 files and 1,474 tests, plus 1 file and 2 tests; pnpm -F @astryxdesign/core typecheck and ESLint on the changed file both pass).
  • No jsdom red test is possible, because React drops a same-value update before it renders — verified: render counts are identical for the base and the head hook while dispatch counts differ.
  • One hook file, with no API, record or output change — verified: the repository's own API generator reports no row from this patch.
  • The release note's claim that the hook returns the same values as before — verified by the probe above.
  • Public text contains no internal context — verified by a scan of the title, body, branch, commit message and every added line.

Files:

  • packages/core/src/Text/useTruncation.ts — clear, with the INV10 reporting gap above and the duplicate-helper note.
  • .changeset/text-truncation-no-op-dispatch.md — the category note above; the sentence itself is accurate.

Automated review (maintainer link)

Comment thread packages/core/src/Text/useTruncation.ts Resolved
// sets nothing, so a list that mounts many texts dispatches no updates
// that would change nothing.
const shownRef = useRef({isTruncated: false, fullText: ''});
const setIsTruncated = useCallback((value: boolean) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking: packages/core/src/hooks/useScrollableArea.ts:208 already has setIfChanged(last, set, value) with the same body and the same reason in its comment. One shared helper under hooks/ would keep the two from drifting.

The changeset is a performance change with identical returned values, so
it opens [perf].
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 6fc52db

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved pending CI: CI is still running on this head; lint, typecheck, build, visual regression and most test shards have passed.

The touched-components audit failed when its repository checkout timed out, before any audit ran, so it needs a re-run; nothing in this change causes it.

The patch is unchanged since the last review, and the hook still returns the same values at the same times while skipping updates that would change nothing.

  • Non-blocking: packages/core/src/hooks/useScrollableArea.ts already has a private setIfChanged with the same body as the new setters, so one shared helper under hooks/ would keep the two from drifting.
Claims and files checked

Review mode: same-head; reason: none

  • Changed rules (0): none.
  • Claims:
    • Title, a measurement that finds the same result sets no state: verified, useTruncation.ts:85-96 skips a value equal to the one last set.
    • Release note, an unchanged measurement no longer schedules a state update: verified, useTruncation.ts:85-96.
    • Release note, useTruncation returns the same values as before: verified, every dispatch is a plain value, so skipping an equal one never changes the committed state; the consumer suites pass.
    • Release note, a patch note filed under Performance: verified, perf is one of the repository's changeset categories and the changeset check passes.
    • Description, wide windowed Tables render each default cell as a single-line truncating Text: verified, Table/BaseTable.tsx:277.
    • Description, before this change every measurement set both values even when unchanged: verified against the merge base's unconditional setter calls.
    • Description, after it a same-value measurement dispatches nothing and the hook's output and timing are unchanged: verified, useTruncation.ts:79-201.
    • Description, the remaining updates are each new cell's first text and the reset when an element detaches: verified from the code paths.
    • Description, real-browser update counts and timings per range step, alone and combined with the companion changes: not reproduced here (they need a real-browser harness and the companion pull requests); consistent with the code.
    • Description, the column-windowing timing target it cites (range at most 4 ms and no-op at most 2 ms at 1,000 columns): verified, it matches the Table column-virtualization record's timing target, which this pull request does not claim on its own.
    • Description, first-load gzip deltas on the four reference pages, each inside the 0.3 KB allowance: verified within compressor variance, +37, +36, +36 and +40 B here.
    • Description, the consumer suites (61 files, 1,476 tests), typecheck and lint pass: verified on this head.
    • Description, jsdom cannot see these dispatches: consistent with React's eager bailout; no render count changes there.
    • Description, one hook file with no API, record or output change: verified; the API change report lists no row.
    • Description, the overlapping server-rendering change also touches this hook: verified.
    • Description, public text carries no internal context: verified.
    • Description, the land path (approval of this head, the spec stamp, CI, then the merge queue): consistent; the spec stamp for this head is present.
  • Files:
    • packages/core/src/Text/useTruncation.ts: clear, with the non-blocking helper note above.
    • .changeset/text-truncation-no-op-dispatch.md: clear.

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as ready for review November 17, 2026 05:06
@cixzhang
cixzhang marked this pull request as draft November 17, 2026 16:37
@cixzhang
cixzhang marked this pull request as ready for review November 17, 2026 16:37
@cixzhang
cixzhang merged commit 93047f8 into main Nov 17, 2026
286 of 294 checks passed
@github-actions
github-actions Bot deleted the l0/text-truncation-no-op-dispatch branch November 18, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — 6fc52db1 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant