fix(load): raise large-file preview threshold from 50KB to 5MB - #554
Merged
PathGao merged 2 commits intoAug 8, 2026
Merged
Conversation
The 50KB two-stage load threshold was never measured. On a 121KB file the full read is 0.032ms vs 0.022ms for the first 50KB — a 0.01ms difference. The mechanism only earns its keep on multi-MB files (roughly two orders of magnitude above where it currently engages), yet the 50KB threshold means every document over ~50KB incurs the complexity of isTruncated flags, revision guards, and save refusals. At 5MB the threshold still protects genuine large files while letting 99.9% of real-world Markdown documents bypass the entire two-stage path. Tests are decoupled from the threshold: the preview mock always returns isFull=false regardless of content size, so the test exercises the mechanism without needing multi-MB test strings.
…vision test PR sftwrdotdev#553 added the onPartialCopySaved callback to DocumentSessionOptions. The test stub in largeFileLoadRevision.test.ts was missing it, causing svelte-check to fail.
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.
Problem
The 50KB two-stage load threshold was never measured. On a 121KB file
the full read is 0.032ms vs 0.022ms for the first 50KB — a 0.01ms
difference. The mechanism only earns its keep on multi-MB files (roughly
two orders of magnitude above where it currently engages), yet the
50KB threshold means every document over ~50KB incurs the complexity of
isTruncatedflags, revision guards, and save refusals.This directly contributed to #547: the race condition between two startup
loads only matters because the preview slice exists at all for files this
small.
Change
Raise
maxBytesfrom50000to5_000_000in the preview read path.At 5MB the threshold still protects genuine large files while letting
99.9% of real-world Markdown documents bypass the entire two-stage path.
Tests are decoupled from the threshold: the preview mock always returns
isFull=falseregardless of content size, so the test exercises themechanism without needing multi-MB test strings.
Verification
npm test— 940 pass / 0 fail