perf(mermaid): keep scrolling and hidden tabs off the render queue
Follow-up to the iframe isolation: after that fix a 31-diagram document still felt janky while scrolling. The remaining cost was work competing with the scroll gesture: - background diagram renders kept running during scroll (each one injects an SVG, runs DOM passes and lays out); - hidden native tabs kept warming diagrams (tab bodies are keepMounted); - the inline-HTML and heading-anchor MutationObservers ran a full-document scan per mutation (measured 8-15 ms per pass, dozens of passes when a document swaps its diagrams in); - initial near-viewport detection read one rect per diagram between DOM writes, forcing a layout per diagram; - off-screen rendered SVGs still participated in layout and paint. The queue now pauses background work for 350 ms after the last captured scroll event, and only schedules renders whose preview is visible (IntersectionObserver gate per preview; hidden tabs keep placeholders and wake the queue when shown again, and unmounting a preview drops its queued tasks). The two mutation passes coalesce bursts into one 80 ms pass. Initial priorities come from one batched rect read before the swap writes. .mermaidWrap gains content-visibility:auto + contain-intrinsic-size + contain:layout paint style, so off-screen diagrams leave layout and paint. Visible diagrams still render on demand, every diagram is still eventually rendered, and nothing falls back to a code block.
This commit is contained in:
1 parent
fe06211775
commit
aa198d7921
7 files changed
+195
-37
No files matched your search
@@ -1872,6 +1872,15 @@ body[data-dsh-sidebar-dragging] .bottomPanel {
|
||||
border-radius: 6px;
|
||||
background: var(--dsw-alias-bg-layer-1);
|
||||
overflow: hidden;
|
||||
/* Scroll performance: a rendered diagram is a large SVG. Skip layout and
|
||||
paint for the diagrams outside the viewport (a diagram-heavy article can
|
||||
hold dozens) and remember the measured height once a block has been on
|
||||
screen, so scrolling past already-rendered diagrams costs nothing. */
|
||||
content-visibility: auto;
|
||||
contain-intrinsic-size: auto 240px;
|
||||
/* Isolate the box: a diagram landing must not invalidate the layout or paint
|
||||
of the surrounding article. */
|
||||
contain: layout paint style;
|
||||
}
|
||||
|
||||
.mermaidHeader {
|
||||
|
||||
Reference in new issue
Block a user