Skip to content

fix: #5860 reduce layout work when switching large files - #5863

Merged
Jocs merged 1 commit into
developfrom
fix/5860-large-file-tab-switch
Oct 23, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/5860-large-file-tab-switch

Conversation

@Jocs

@Jocs Jocs commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Closes #5860.

Summary

Switching back to a large Markdown tab rebuilds the editor and then performs avoidable work on the connected document: assigning contentEditable even when its value is unchanged, rewriting the same attribute on content nodes, and hiding the editor before restoring its scroll position. The visibility change forces additional layout work for the entire document.

  • Skip editability writes when the existing value already matches, while preserving read-only transitions.
  • Keep the editor visible during the synchronous rebuild and restore scrolling in the existing animation-frame callback before paint.
  • Add regressions for editability across document loads and repeated large-table tab switches preserving scroll position.

Performance evidence

Measured in the built Electron app on macOS using the author's original 265,184-byte attachment from #5860, alternating with a roughly 20 KB document. Timing runs from tab activation through two animation frames, with CPU profiling enabled for both versions.

Switching to the original large document Before After
Four samples (ms) 450.5, 424.9, 444.6, 425.2 327.9, 323.1, 295.8, 288.9
Mean (ms) 436.3 308.9

This reduces the measured tab-switch latency by about 29%. The baseline profile identified _refreshReadingPresentation and the scroll/visibility restoration layout work as major costs. The original attachment and profiling artifacts are kept outside the checkout.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New tests added
  • Manually tested on: macOS (built Electron application, original issue attachment)
  • pnpm run build:unpack
  • pnpm run lint (no errors; existing warnings)
  • pnpm run typecheck
  • pnpm -C packages/muya lint
  • pnpm -C packages/muya lint:types
  • pnpm -C packages/muya test — 2,871 tests passed
  • pnpm test:unit — 1,209 tests passed
  • Desktop Playwright: large-file-tabs.spec.ts, cli-read-only.spec.ts, and external-reload-undo.spec.ts — 7 tests passed

Notes for reviewers

The reported Windows 11 / MarkText 0.23.0 freeze of 6–7 seconds was not reproduced on this macOS / current-development-branch environment. This PR addresses measured overhead in the current code; it does not establish that the original Windows scenario is fully resolved. This PR closes #5860 on merge. The issue comment records these measurements and the recently merged performance improvements (#4942 and #5856), and asks the reporter to retest a build containing the changes and reopen the issue if the Windows freeze persists.


By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@Jocs Jocs mentioned this pull request Oct 23, 2026
1 task done
@github-actions

Copy link
Copy Markdown
Contributor

Build artifacts for PR #5863:

Run: https://github.com/marktext/marktext/actions/runs/39905536469

Artifact Size Link
marktext-windows-arm64 291.5 MB Download
marktext-macos-x64 314.1 MB Download
marktext-linux-arm64 523.2 MB Download
marktext-macos-arm64 300.7 MB Download
marktext-linux-x64 669.1 MB Download
marktext-windows-x64 299.6 MB Download

@Jocs
Jocs merged commit a6a7843 into develop Oct 23, 2026
19 checks passed
@Jocs
Jocs deleted the fix/5860-large-file-tab-switch branch October 23, 2026 08:32
Zane-0x5a added a commit to Zane-0x5a/marktext that referenced this pull request Oct 27, 2026
Brings in v0.22.0 and v0.23.0 and the start of 0.24.0: Electron 45,
GitHub Alerts, foldable headings, per-tab reading mode and --read-only,
the docked document outline, multiple folder roots, preview tabs, recent
files in quick open, Italian, and the large-document fixes of marktext#4942 and
marktext#5863.

Conflicts:

- muya state/inlineRenderer: marktext#4942 caches reference definitions per
  candidate state, which supersedes the fork's per-revision cache. Took
  upstream's; the fork's display math cache in mathPreview stays.
- editor.vue: kept the fork's deferred content snapshot (no getState()
  deep clone per keystroke), document virtualization and camera, on top
  of upstream's reading mode, shortcut resolvers and image drop. The
  json-change handler keeps upstream's loadingContent/readOnly guard,
  the source handoff and reload take upstream's loadingContent blocks,
  and scrollToHeader reveals folded headings before following the
  target. publishContentChange uses getSelectionState().
- Print/PDF: the fork's paged preview replaces MarkdownPrint and the
  printToPDF export path, so printService, its specs and the pdf branch
  of handleResponseForExport keep the fork's side. marktext#3323 moved image
  resolution into the engine; exportHtml drops its own image rewrite and
  keeps the fork's rendered-heading TOC.
- marktext#5802's assertExportDestination moves to main/filesystem so Save PDF in
  the preview refuses the source document too.
- syntheticHistory keeps the 53-bit cyrb53 hash over upstream's BigInt
  FNV-64 (~6 ms per key on a 500 KB note); the store keeps isSameList
  and drops deep-equal.
- Sidebar rows keep draggable alongside preview tabs; locales keep both
  printPreview and readingMode, and it.json gets the printPreview strings.

Merge adjustments:

- SET_READ_ONLY publishes the pending snapshot first: a read-only tab
  drops content changes, so an edit made within 150 ms of entering
  reading mode would otherwise be missing from the tab.
- marktext#5798 moved notices to the bottom-right corner, over the preview's
  Save PDF and Print buttons, and an export notice stays while hovered.
  The preview lifts notices clear of its actions while it is open.
- Specs: the docked outline is expanded by default and narrows the
  column, so the virtualization specs open it only when it is closed,
  measure the settled position and place their target inside the
  viewport. The camera specs press Control once before measuring,
  because since marktext#5878 the first key press re-renders the caret's heading
  with its marks shown.

Verified on Windows 11 (175%): typecheck, lint, the desktop unit suite
(1467) and the muya unit suite (3978) pass. In background windows the
e2e suite (514 passed, 45 failed) fails only where a build of
upstream/develop fails on this machine too (copy-anchor-link,
document-outline, image clipboard/relative path, 5394, 5685,
toc-active-heading, outline-layout, ...: 56 cases in 19 specs there),
plus media-viewer cases that flake on both when the 1 px image's resize
bar takes the click. print-preview, export-pdf, document-virtualization
and sidebar-file-drag pass, and editor-camera passes on screen.
reading-mode:54 needs the camera focus fix in the next commit.
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.

[Bug] Slow reaction to large file

1 participant