Skip to content

feat(pdf): skip laying out and painting an off-screen page - #750

Merged
andiwand merged 1 commit into
mainfrom
feat/pdf-skip-offscreen-pages
Aug 27, 2026
Merged

feat(pdf): skip laying out and painting an off-screen page#750
andiwand merged 1 commit into
mainfrom
feat/pdf-skip-offscreen-pages

Conversation

@andiwand

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

Stacked on #749.

A body zoom relays out every element on every page at every step. On a drawing-heavy pdf that is tens of thousands of SVG paths per page. content-visibility:auto on the page box lets the browser skip an off-screen page entirely.

One declaration. The box already states its own width and height, so it needs no contain-intrinsic-size and the scroll geometry does not move.

Measured

Sunfun_Melina_BBQ_Pavillion (11 pages, 181k DOM nodes, 172k <path>), Chrome over loopback, rule in the stylesheet as shipped:

before after
domComplete 4316 ms 2256 ms
load event 6018 ms 2329 ms
zoom frame, median 340 ms 48 ms
zoom frame, max 656 ms 54 ms
scrollHeight 12540 12540

Render-neutral

  • All 255 rendered pages of the 11-file pdf corpus rasterised and scored against ghostscript: identical to the digit, before and after.
  • getBoundingClientRect() inside a skipped page still returns real geometry, so search highlight positioning is unaffected — checked on the last page of an 11-page document (794x1123 @ top 11401).
  • Print still emits all 9 pages with full content. The residual pixel delta is text antialiasing; a control printing the same file twice is already nondeterministic.

Not in this PR

Swapping body{zoom} for transform:scale() removes the remaining layout cost entirely (~48ms -> ~12ms per frame), but it touches the rectsZoomed webkit probe in viewport.js and the browser checks, so it belongs on its own.

content-visibility needs Safari 18+ in WKWebView; older webviews ignore it and get today's behaviour.

Base automatically changed from fix/pdf-simple-font-code-width to main August 27, 2026 19:39
A body zoom relaid out every page at every step. On a file whose pages hold
tens of thousands of svg paths that is ~340ms a step; `content-visibility:auto`
takes it to ~50ms and halves the time to open. The page box states its own
width and height, so it needs no `contain-intrinsic-size` and the scroll
geometry is unchanged.

Render-neutral: the 255-page raster comparison scores identically, and print
still emits every page.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169dUoxqhqfi7ZU5ei8b9ov
@andiwand
andiwand force-pushed the feat/pdf-skip-offscreen-pages branch from 1dd36d5 to b33dc77 Compare August 27, 2026 20:56
@andiwand
andiwand merged commit 82c4f88 into main Aug 27, 2026
25 checks passed
@andiwand
andiwand deleted the feat/pdf-skip-offscreen-pages branch August 27, 2026 20:56
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