Skip to content

fix(load): raise large-file preview threshold from 50KB to 5MB - #554

Merged
PathGao merged 2 commits into
sftwrdotdev:masterfrom
PathGao:fix/raise-large-file-threshold
Aug 8, 2026
Merged

fix(load): raise large-file preview threshold from 50KB to 5MB#554
PathGao merged 2 commits into
sftwrdotdev:masterfrom
PathGao:fix/raise-large-file-threshold

Conversation

@PathGao

@PathGao PathGao commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

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
isTruncated flags, 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 maxBytes from 50000 to 5_000_000 in 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=false regardless of content size, so the test exercises the
mechanism without needing multi-MB test strings.

Verification

npm test — 940 pass / 0 fail

PathGao added 2 commits August 8, 2026 21:11
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.
@PathGao
PathGao merged commit d4db3df into sftwrdotdev:master Aug 8, 2026
4 checks passed
@PathGao
PathGao deleted the fix/raise-large-file-threshold branch August 8, 2026 14:53
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