Skip to content

PDF: the next page drawn sharp, and zooming waits less (#388) - #412

Merged
Joost-8 merged 4 commits into
mainfrom
issue-388-pdf-neighbours
Dec 4, 2026
Merged

Joost-8 merged 4 commits into
mainfrom
issue-388-pdf-neighbours

Conversation

@Joost-8

@Joost-8 Joost-8 commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Fixes #388. Part of discussion #400 (PDF zoom lag).

What changed

  • The page beside the one you read is drawn sharp (Next page is not rendered when viewing near the edge of the current page #388). Zoomed so the next page shows at the edge, that strip only ever got the page's reduced image. At rest, with the PDF worker, it now gets tiles at the view's own resolution. It asks for them only while everything else that is wanted fits in 85 % of the cache's hard budget, so nothing extra is asked for while you scroll or zoom.
  • Each zoom's sharpen fade no longer copies the page layer. Renderer.coverDry puts a new canvas in place of the old one and keeps the old one as the fade's cover. The copy made the iPad wait for WebKit to finish the whole layer.
  • A tile draws only the part of a PDF image it shows (drawWithin, in canvas/night.ts), and so does the dark-page pass. The pixels are the same, and far less image is drawn mid-zoom.

Proof

All on Joost's iPad over the bridge.

  • Sharpness of the next page's strip (edge energy, three spots): 6,600–7,600 before, 14,000–16,000 after. The page being read scores 15,600–16,100. Cost: the PDF cache goes from 50 to 58 MB, against a hard budget of 96.
  • Worst frame per pinch on the network book (same session, fresh pages, alternating builds): 177–206 ms with the old fade copy, 85–161 ms with the swap. Before this branch it reached 846–868 ms.
  • drawWithin (light pages, four runs per build): the most image drawn in one frame fell from 60–150 MP to at most 29 MP. The worst frame per run is unchanged: 238–283 ms before, 223–271 ms after. That frame is the zoom-out landing on the page grid, so this is less work, not the fix for the stalls. The dark-page pass was changed after the device runs and is covered by tests only.
  • Tests: strips in pdf-backdrop.test.ts, coverDry in renderer-overscan.test.ts, shownRegion in pdf-raster.test.ts, source-rect draws in pdf-display.test.ts and in the dark-page pass in night.test.ts.
  • npm run gates: all 11 steps green. On an earlier run, library-view.test.ts failed once under load; it's a read-queue timing test this branch doesn't touch, and it passed 3 of 3 alone.
  • Reviewer agent: two rounds. The first found nothing. The second found that the dark-page pass still drew whole images (fixed) and that the commit message claimed a stall fix (reworded). Still open from it: whether WebKit samples outside a source rect when it shrinks one. If it clamps, a faint seam could show at tile edges until the right raster lands. Not seen in the iPad shots.
  • check.mjs --changed: no finding in PDF painting. Its 7 text-ellipsis groups are in scenes this branch doesn't touch; the nightly already reports 6 such groups on main.
  • Review page: https://claude.ai/artifact/9FN1Kchw9yZixPWcc5zs2D

Test on the device

  1. Open a PDF notebook with small print, pages down. Zoom so the next page's top shows at the foot of the screen, then wait a second: its text is as sharp as the page above.
  2. In a big PDF (the network book), pinch in and out on pages you haven't opened yet: the pinch should no longer stop for most of a second.
  3. Zoom far in on a page and pan: the page stays sharp and nothing flickers or goes blank.

Not verified

  • About once per 15 s of pinching, the iPad still froze for 0.3–2.5 s in earlier runs. It happened with PDF rendering held too, and no JS callback ran over 50 ms, so it looks like WebKit finishing the frame. It is not compared on main, and tonight's runs didn't show one.
  • The crashes in more requests #400 (on launch, while zooming) did not happen.
  • Popout windows were not tested.
  • The reviewer's notes: whole= on the overlay now counts the fades too; a strip landing can start a second fade right after the first; the ink-surface side of the swap has no test of its own.
  • Without the PDF worker (pdf.js on the main thread), the strip keeps its reduced image, as before.

🤖 Generated with Claude Code

Joost-8 and others added 4 commits December 3, 2026 00:15
…de copies nothing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Zoomed in, every tile drew its page image and detail patches whole under a
clip, and dark pages drew them whole a second time: 60-150 megapixels of
source in a frame on the iPad (discussion #400). drawWithin (canvas/night.ts)
draws the source rect the tile shows, mapped as before: at most 29 MP. The
worst frame per pinch did not change (238-283 ms before, 223-271 after), so
this is less work, not the fix for the remaining stalls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Joost-8
Joost-8 marked this pull request as ready for review December 4, 2026 01:50
@Joost-8
Joost-8 merged commit c9d76e1 into main Dec 4, 2026
1 check passed
@Joost-8
Joost-8 deleted the issue-388-pdf-neighbours branch December 4, 2026 01:50
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.

Next page is not rendered when viewing near the edge of the current page

1 participant