Repository navigation
perf: skip redundant image scans in image-free Markdown previews - #26240
Merged
Merged
Conversation
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.
ELI5
Opening a Markdown preview needlessly parsed the document a second time to look for images, even when it could not contain a Markdown image. Skip that image-prewarm pass when the text has no
!.What Changed
Add one early condition in the existing image candidate extractor. Markdown images and image references require a literal
!; documents containing it retain the same parser, image routing, candidate limit, and scheduling. Raw HTML images were already excluded from prewarming.Why
This removes synchronous work from the preview effect without changing rendering or introducing a cache with invalidation rules. Seven alternating warm trials of the actual exported prewarm function, including scheduling and completion, measured real repository documents:
These are Node measurements of image prewarming, not total React rendering or typing latency. Image-bearing and bang-bearing controls still use the full parser; their timings varied, so this is not a claim of faster parsing for those documents.
Linked Issue
No linked issue; maintainer performance audit.
Visual Proof
Actual
MarkdownPreviewand its source-foundation hook in hidden Electron, with a real 119,287-byte tracked document. Complete rendered HTML hashes match; the prewarm parser count changes from one to zero, with no image IPC in either version. Appending a Markdown image still decodes it and reads it once in both versions. The image read boundary uses controlled IPC returning a valid PNG.Before:

After:

Testing
macOS: three new parser-admission cases fail on baseline (13 existing tests pass), then all 16 pass. The complete editor suite passes: 325 files, 2,451 tests, with two existing skipped files/three skipped tests. Web typecheck, changed-code quality, formatting, and fresh Electron build pass. Temporary qualification also checks 8,177 extraction/scheduler comparisons covering paths, limits, runtime owners, direct/reference/GFM images, escapes, entities, frontmatter, and HTML exclusions. Existing concurrency and cancellation tests pass. No live SSH host or Windows/Linux desktop run; routing and platform path behavior remain unchanged and are covered by existing tests.
Review
Independent source and parser-grammar review passed. Root reviewed the diff and both rendered screenshots.
Agent skill upstream boundary
Notes
No new state, IPC, or wire fields. Folder and remote document ownership still use the existing image loader. The intermittent Codex typing pause remains unreproduced; this PR does not claim to fix it. Combined with all 34 audit changes: 447 affected test files / 3,727 tests pass (two existing skipped files / 13 skipped tests), full
pnpm tcpasses, and the 106-file changed-code quality gate reports no new findings. All required selected hosted checks pass.Checklist