Are multiple inactive EditorViews inefficient?

I’ve been building a simple IDE using CodeMirror with Electron, and CodeMirror has been fantastic thus far. I’m facing a choice on how to implement multiple tabs, and was curious to hear thoughts on which makes more sense.

The first way would be using a single EditorView. Whenever the tab changes, we save the jsonified EditorState of the file in some store like Redux, then load the EditorState of the new tab into the view.

The second way would be maintaining an EditorView for every open tab and just hiding/detaching it from the DOM when not used.

The reason the second may be better is:

  1. It is potentially difficult to serialize all relevant aspects of the EditorState
  2. There are use cases for which I may want to dispatch changes to opened files in the background. For example, having a global lint panel with a button to run all quick actions across open tabs.

But the main reason I am worried is that it may incur some overhead to have a significant number of EditorViews (though almost all will be completely inactive). And maybe it is just bad practice to do this.

Any thoughts on both approaches?

Multiple views should be no problem. Except for some (low-complexity) global event handlers that a live view holds, there should be about 0 CPU use overhead for out-of-view editor instances.

1 Like