Description
[spin off from https://github.com/cben/mathdown/issues/56#issuecomment-108872386]
Using heap profiling on my ~100K document,
I see Chrome heap dump usage mainly consists of 50~60MB of DOM and ~40MB of CodeMirror.Lines arranged in a b-tree. It's similar with checking and without.
One would expect the partial DOM to be much smaller than CodeMirror's full b-tree, but this is a math-heavy document. I've tried switching MathJax to SVG output with similar results. But actually, it's sensitive to viewport. Scrolling to a math-free portion and taking a snapshot, there's still similar amount of DOM but it's in small detached fragements.
Can we do better?
Without math rendering, there is only 9MB of DOM and 360KB of CodeMirror DOM!
Can we somehow avoid keeping storing off-screen math in rendered DOM form?
KaTeX might help. Not sure its math output is much cheaper, but it might be fast enough to call render() from CM's renderLine
callback, materializing it only for visible part.
If that helps, in principle we could use MathJax to render math to HTML strings, keep them in some hash, and replace renderLine
.