Lazy rendering for ProseMirror

Hey @marijn ,

In CodeMirror 6 design docs you mentioned lazy rendering. I wonder if you tried implementing similar performance optimisations for ProseMirror.

What are the potential pitfalls if one attempted to do that? First thing that comes to mind is searching within the document (cmd+f), printing (cmd+p) and fast scrolling. I am very interested to hear how did you solve those problems in CodeMirror.

1 Like

Nope. This is really complex to get right, even for flat text like in CodeMirror. ProseMirror is already complex for other reasons, so I intentionally shied away from adding another source of bloat and fragility.

Neither of those are solved. For search, you’ll want to provide our own custom dialog. For print, you should be able to use the beforeprint command to force-render the whole document, but we haven’t implemented that (I just filed an issue).

The main difficulty are with reacting to scrolling in such a way that the visible part of the document is always drawn, which requires knowing the height of everything, even the parts that you never rendered. In code editing, it is not uncommon to view multi-megabyte files (build artifacts, data sets), and this appears to be less common in rich text editing—but yes, if you try to edit a whole book as a single document in ProseMirror, you’ll probably notice a slowdown and a lot of memory used.