Skip to content

perf(core): measure text autofit for a whole slide at once - #150

Merged
sadmann7 merged 2 commits into
mainfrom
sadman/perf-core-autofit-batch
Nov 30, 2026
Merged

sadmann7 merged 2 commits into
mainfrom
sadman/perf-core-autofit-batch

Conversation

@sadmann7

Copy link
Copy Markdown
Owner

Text autofit wrote styles and then read clientWidth and scrollHeight for one text box at a time, so every autofit box forced its own layout of the slide, both during renderSlide and again in its own deferred pass two frames later. That was the largest single cost of rendering a deck: 1,041 ms of self time on the 300-slide bench deck.

  • renderer/autofit.ts splits a box's measurement into phases (prepare, measure, unwrapped measure, apply). runAutofitJobs runs each phase for every box before the next phase starts, so a slide costs two layouts instead of two per box.
  • renderSlide collects its boxes' jobs and runs them once every node is mounted. The deferred passes for boxes scheduled in the same frame run together in the frame their own double requestAnimationFrame would have used. A job scheduled twice in a batch runs once.
  • The style writes, restores and conditions are unchanged. Shapes are absolutely positioned, so one box's writes can't move another's measurements. A box whose measurement throws drops out without stopping the others.
  • On the 300-slide deck, forced-layout self time drops from 1,041 ms to 621 ms in a CPU profile.
  • Core only. Nothing diceui syncs is touched.

pnpm bench --runs 9 --against <main build>: the two builds alternate run by run, median of 9, Chromium headless shell 156 on Linux. Times in milliseconds:

deck slides open → first slide open → all slides
small 8 65 → 64 209 → 197 (1.1×)
text-heavy 60 82 → 76 604 → 516 (1.2×)
image-heavy 40 145 → 150 457 → 452
many-slides 300 315 → 331 3505 → 2870 (1.2×)
shapes-charts 40 216 → 223 1071 → 969 (1.1×)

An A/A run moves these by up to ±10%, so time to first slide is unchanged. The gain is in rendering every slide.

pnpm bench --shots before and after, compared with pnpm bench:diff: 448 of 448 slides identical pixel for pixel.

Not shown:

  • Firefox and Safari not run; the Chromium e2e project passes (72 passed).
  • Embedded fonts aren't loaded by the bench.

@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
pptx Ready Ready Preview Nov 30, 2026 2:29pm UTC

Request Review

@sadmann7
sadmann7 merged commit 01173b5 into main Nov 30, 2026
7 checks passed
@sadmann7
sadmann7 deleted the sadman/perf-core-autofit-batch branch November 30, 2026 14:43

This branch was successfully deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant