Skip to content

fix(html): what a review of lazy loading found - #1267

Merged
andiwand merged 4 commits into
mainfrom
fix/lazy-loading-review
Oct 25, 2026
Merged

andiwand merged 4 commits into
mainfrom
fix/lazy-loading-review

Conversation

@andiwand

@andiwand andiwand commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Three reviewers read the lazy loading work of #1246 to #1265: the core C++, the pdf writer, and the frontend scripts. This PR fixes what they found, and advances the reference output.

Search and loading in the page

  • A search keeps the hits of a chunk that has not loaded as one run {chunk, count}, not one object for each hit. viewport.js keeps the index text folded, because only a search reads it. On a million lines, a search for "e" counts 5.1 M hits in 83 ms, and the heap is 225 MB.
  • The index scripts of a group whose chunks have all loaded are not loaded, and the text of a chunk that loaded is not kept.
  • fold and the fold of the index take a surrogate pair as one character. Before, 𐐨 found an uppercase 𐐀 in a loaded chunk but not in the index.
  • A search that a new one replaces resolves its searchDone with null, not with the count of the new search.
  • odr.chunks.show observes the chunk again, so the observer takes it back once it is far. Without IntersectionObserver, a chunk now loads. The observer takes the document as its root where the browser can, so its margin also works in a frame of another origin.
  • A sheet with lazy_layout off spills a written value without a TypeError in reflow. A chunk that loads with a merge makes the sheet read its cells as merged. Before, a cell right of the merge named the wrong column.
  • A pdf page that loads draws its annotations again. odr.chunks.fill replaced the overlay.

Core

  • A text chunk and an index script read a slice of the text, not a copy of all of it. bring_offline of a million lines now takes 3.9 s, not 9 s.
  • text-search/<n>.js with a huge n no longer wraps to group 0.
  • The pdf service guards its linked resources with a mutex of their own. A render of another view appended to the list while exists, mimetype or write read it. This race is older than lazy loading, but page scripts make it frequent.
  • The text render of a pdf page for the index reads no image. An image-heavy pdf builds a group in 0.2 s, not 0.73 s. A page script keeps its text for the index.
  • A linked SVM image states no file(), because what it writes is SVG.
  • The group size of a search index is one constant for every view.

Docs and bindings

  • The lazy_loading comments name every view.
  • The npm package takes lazyLayout.
  • The plan lists the known limits: a sheet with a merge open to the end, the index/DOM gaps, the page scripts of a pdf, and resource lifetime.

Checked

  • The full suite passes (2541, 6 skipped), and clang-tidy is clean on the changed sources.
  • Every browser page passes, with new checks for the astral fold, a late merge, a sheet without chunks, and annotations on a page that fills.

Reference output (1d5950ad public, 29f730f1 private): 161 and 166 pages change. Each one, with the chunk classes and style removed and the two new error codes taken out, is the page as it was. Also changed: the resources/ scripts.

Review fixes

  • Three new lines in search.js and viewport.js went to 102 columns. They are wrapped below 86, as the rest of these files. The step to a hit in a chunk that loaded names its offset again.
  • I checked that the two reference pins are on the remote main of the output repositories, that the lock order is always m_mutex before m_resources_mutex, and that the pdf resource fonts are in an unordered_map, as the known limits say.
  • Tested: the html, pdf, text, sheet and http gtests (771), and every page of viewport, sheet, annotation, text and bridge. sheet/dates.html and sheet/formula-words.html passed on a second run, after the known load-timing flake.

🤖 Generated with Claude Code
https://claude.ai/code/session_01YHNzLmVv1mFWfPitHASucN

andiwand and others added 3 commits October 25, 2026 10:07
Search and loading in the page:
- A search keeps the hits of a chunk that has not loaded as one run,
  not one object for each hit, and viewport.js keeps the index text
  folded, so a search for "e" over a million lines counts 5.1 M hits in
  83 ms.
- The index scripts of a group whose chunks have all loaded are not
  loaded, and the text of a chunk that loaded is not kept.
- fold and the fold of the index take a surrogate pair as one
  character, so an astral capital counts the same in both.
- A search that a new one replaces resolves its searchDone with null.
- odr.chunks.show observes the chunk anew, so the observer takes it back
  once it is far. Without IntersectionObserver a chunk loads too. The
  observer takes the document as its root, where the browser can, so
  the margin works in a frame of another origin.
- A sheet with no chunks (lazy_layout off) spills a written value
  without a TypeError, and a chunk that loads with a merge makes the
  sheet read its cells as merged.
- A pdf page that loads draws its annotations again.

Core:
- A text chunk and an index script read a slice of the text, not a copy
  of all of it, so bring_offline of a million lines takes 3.9 s, not 9 s.
- text-search/<n>.js with a huge n no longer wraps to group 0.
- The pdf service guards its linked resources with a mutex of their
  own; a render of another view appended to the list while it was read.
- The text render of a pdf page for the index reads no image, and a
  page script keeps its text for the index.
- A linked SVM image states no file, because what it writes is SVG.
- The group size of a search index is one constant for every view.

Docs: the lazy_loading comments name every view, the npm package takes
lazyLayout, and the plan lists the known limits.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017QtawyvLP2SCnoBtnVfFed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017QtawyvLP2SCnoBtnVfFed
Each page script re-encodes its fonts for its own runs, as a page view
does today; a digest names the files so that pages whose votes agree
share one.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017QtawyvLP2SCnoBtnVfFed
@andiwand
andiwand force-pushed the fix/lazy-loading-review branch from d40d4a9 to 44cd7dd Compare October 25, 2026 09:07
Three new lines in search.js and viewport.js went to 102 columns, where
these files stay below 86. The step to a hit in a chunk that loaded names
its offset again, as before the review.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YHNzLmVv1mFWfPitHASucN
@andiwand
andiwand merged commit fd7e85c into main Oct 25, 2026
16 checks passed
@andiwand
andiwand deleted the fix/lazy-loading-review branch October 25, 2026 09:11
andiwand added a commit that referenced this pull request Oct 25, 2026
…1269)

The format pass of #1267 wrapped long lines in search.js and
viewport.js after the references were regenerated. No page changes.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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