Skip to content

perf: skip redundant image scans in image-free Markdown previews - #26240

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-markdown-imagefree-prewarm
Oct 8, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-markdown-imagefree-prewarm

Conversation

@nwparker

@nwparker nwparker commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

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:

Document bytes Before After
18,415 3.016 ms 0.003 ms
39,110 11.267 ms 0.004 ms
119,287 42.852 ms 0.010 ms

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 MarkdownPreview and 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:
before.png

After:
after.png

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

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

  • Not applicable; no upstream skill-installer code or artifacts copied.

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 tc passes, and the 106-file changed-code quality gate reports no new findings. All required selected hosted checks pass.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • Relevant tests, typecheck, quality, format, and build pass; remaining checks in CI

@nwparker
nwparker merged commit 4d7193c into main Oct 8, 2026
30 checks passed
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