feat(browser-repl): add virtualisation in shell output COMPASS-7567 #2329
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In this PR, I am rendering the ShellOutput in a virtual list, where shell input (editor/password prompt - ShellInputPrompt) is rendered outside of it. Initially I made it (shell input) as part of the list. However with that change, so many other things needed to be taken care of - like persisting password prompt value, getting focus back to it as its visible. With that, currently we always render the ShellInputPrompt at the top and as data piles up, its pushed down. Once its at the bottom, it continues to stay there and does not scroll away as is currently happening in embedded shell.
Its still in draft for two reasons:
I have been playing with few options regarding this. I tested virtualisation using Codemirror (CM) editor, LG Code component (LG).
Currently we are using CM to render the shell input/output. The setup for this component is expensive in terms of time and memory and as a result user sees CPU spike. The spike is unavoidable if we are rendering especially a large document, where CM needs to parse it for syntax highlighting (which it does only when needed). Except for table outputs in shell (show dbs/collection etc), we mostly render everything using this component - even the scalers.
With virtualising the output using CM, the rendering is pretty fast, however we continue to render a single shell output using one CM instance - which brings in CPU spikes and rendering lags.
@gribnoysup suggested that we explore using LG instead. Its slightly better in terms of performance and rendering but only for smaller documents. For collections with higher document size, CM still performs pretty well (as it has inbuilt virtualisation).
Comparison of performance (time) between CM and LG. In this table, only five docs were queried and everytime shell output was cleared.
(I gave up on LG as it started with slow performance for bigger docs).
I feel we should only use one CM instance to render the shell output where we club all the various types of outputs. Currently we have few special use cases (shell commands) to render:
Among these, Error view is the one where we need to do some special handling as it contains a toggle. This all should be possible if we do a custom grammar for CM and then with
For passwordPrompt, we render this component at the shell input and this will remain unaffected if we use single CM for output.
We also have a special input for password, but we are not rendering it in the shell output list, but rather its part of shell input.