Repository navigation
feat(html): load the later chunks of a text file on demand - #1253
Merged
Merged
Conversation
This is level 3 of `lazy-loading.md` for text files. `HtmlConfig::lazy_loading` (default off) writes each chunk after the first as a script of its own, `text-chunks/<n>.js`. The script puts the lines into the page through `odr.chunks.fill`. `viewport.js` adds the script when the chunk becomes near. Until then the chunk holds the height of its lines. A script loads over HTTP and from a file alike, so one page works in both places: - `bring_offline` writes the chunks beside the page. - The HTTP server serves them through `exists` and `write`, with no route of its own. The service keeps the text and where each chunk starts in it, so a chunk costs in proportion to the chunk. A file of one million lines becomes a page of 485 KB and 3906 scripts. From `file://` it paints its first frame after 67 ms, against 0.85 s at level 1. The HTTP server answers the page in 4 ms and a chunk in 2 ms. An editable render keeps every line in the page, because its log states the whole text. So does a page that is not UTF-8, because a script is UTF-8. `odr.search` finds only the chunks that have loaded. 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
`chunk_of` read any string of digits, so `text-chunks/01.js` and an index that wrapped past the size of `std::size_t` named an existing chunk too. The path must now be the one that `chunk_path` writes. Also add `lazy_loading` to the changelog, state in the design doc that a chunk that has not loaded prints as empty space, and update its status. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YHNzLmVv1mFWfPitHASucN
andiwand
force-pushed
the
feat/text-chunks-on-demand
branch
from
October 24, 2026 20:29
93ad5dc to
949b946
Compare
The text service read the text once and kept it. But `TextFile::edit` changes the text under the service, so a render after an edit showed the text from before it. The wasm test "edits and saves a plain text file" failed. Now only a page that loads its chunks reads the kept text, and every other render reads the text again. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YHNzLmVv1mFWfPitHASucN
The check against `chunk_path` already refuses a path that is not the one it writes, so a loop over the digits is not necessary. `from_chars` also refuses an index that does not fit, where the loop wrapped. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YHNzLmVv1mFWfPitHASucN
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YHNzLmVv1mFWfPitHASucN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Generated with Claude Code
Refs #764.
Summary
This is level 3 of
docs/design/lazy-loading.mdfor text files.HtmlConfig::lazy_loading(default off, needslazy_layout) writes each chunk after the first as a script of its own,text-chunks/<n>.js. The script puts the lines into the page throughodr.chunks.fill(n, html).divwithdata-odr-chunk-src. Itsmin-heightholds the height of its lines, so the page does not move when they come.viewport.jsadds the script when such a chunk becomes near, or whenodr.chunks.showshows it. It removes the script again after it has run.fetch: a script loads over HTTP and fromfile://alike, wherefetchof afile://URL is blocked. So one page works in both places:bring_offlinewrites the chunks beside the page. The view returns them asHtmlResources that render on demand.HttpServerserves them throughHtmlService::existsandwrite, with no new route.std::call_once), so a chunk costs in proportion to the chunk.odr.searchfinds only the chunks that have loaded. It stays an open question in the design doc.script_stringmoved tofrontend.hpp, and it now replaces bytes that are not UTF-8 rather than throwing.Measured with a 1 M-line file:
file://Over HTTP the server answers the page in 4 ms and a chunk in 2 ms. Screenshots show the middle (line 500,001) from
file://and the end (line 1,000,000) over HTTP, both loaded after a scroll.The reference output changes only in
text.css,viewport.jsandspreadsheet.js; the last picks up the reviewer's fix from #1250. Pins: public a0861bb, private 48b541d.Test
html.a_text_file_loads_its_later_chunkscovers:existsfor chunk 1 but not chunk 0 or one past the endtest/browser/viewport/chunks.html(6 checks): a far chunk loads nothing, a near one loads its lines and drops its source and its script, and a shown one loads.tests.htmlstill passes 17.Review fixes
assertFalseof feat(html): add a switch for lazy layout #1251. The rebase keepsassertFalseforlazyLayout, and also uses it forlazyLoading.chunk_ofread any string of digits, sotext-chunks/01.jsand an index that wrapped paststd::size_talso named chunk 1. The path must now be the one thatchunk_pathwrites. The test checks both paths.beforeprintcannot wait for a script. The design doc now lists this under the open questions, and it updates its status.CHANGELOG.mdhas an entry forlazy_loading, with its two limits.TextFile::editchanges the text under the service. So a render after an edit showed the old text, and the wasm test "edits and saves a plain text file" failed. Now only a page that loads its chunks reads the kept text, and every other render reads the text again.html.a_text_file_renders_the_text_of_an_editfails without the fix and passes with it. The wasm node tests pass locally (68).TextFile::edit, the chunks show the text from before the edit. Such a page is not editable, so this needs a host that edits the file from outside the page.test/browser/viewport:tests.htmlgives 17 checks andchunks.html6, all with 0 failed.