CodeMirror 6: Web-Worker-isolated state?

Considering V6’s singleton and isolated state, I think it’s possible to ‘decouple’ the EditorView instance from it’s state and instead dispatch updates through some asynchronous helper functions. I wish to do this because, well, it’s fun, and also because I’m doing some fairly heavy lifting on the DOM on the main thread (very, very fast Markdown live-preview, which itself is already heavily web-workerized and asynchronous) and I would like to isolate the potentially parse-heavy operations into a web-worker.

I would really appreciate some pointers or whatever technical knowledge is needed to make this work. If it isn’t possible, could it be put somewhere on the todo list for later? I know that monaco-editor already does this, so it would be a ‘competitive’ feature to have or have easily supported. It also has the nice bonus where if you screw up your parser, it just freezes the web-worker instead of the whole page!

Not doing this is a conscious decision in this project—serializing/deserializing on worker boundaries is very limiting in the kind of data structures you can (effectively) use, and asynchronicity everywhere makes code a lot more complex, expensive, and error-prone. So I went with a synchronous single-heap approach that takes care not to do too much work during updates.

1 Like

Ah okay, that does seem reasonable. I have noticed how fast CodeMirror V6 is, so props for that. Thanks for the quick response!