-
Notifications
You must be signed in to change notification settings - Fork 3
Description
MultilineValue (actually, mostly LineCollection) seems to contain a lot of hidden cost, and I'm curious about what alternatives have been considered or evaluated.
In particular, I'm looking at MultilineValue#to_s (delegated to LineCollection#text), which has to "reconstruct" the text value from the collection of lines. When dealing with relatively small values this isn't particularly problematic, but does become more so as the value grows. Calling this method every frame (for debugging, or data synchronization reasons) can be detrimental.
While joining the lines after every change is obviously problematic as well, I do wonder about a few other options…
- Use memoization to avoid recomputing
textwhen the lines haven't changed.- This requires a little more cooperation with the mutation behaviors, but may be reasonable.
- Mirror updates to lines against the original input text String.
- That is to say, retain a (mutable) copy of the input text, and write every update to both the lines and that copy of the text.
MultilineValue#to_scan then just return that update copy, with no additional work required.
- Make soft-wrapped "lines" conceptually less concrete.
- The thought I'm trying to express here is that maybe we don't need to treat the value as a collection of
Lines. In general, the lines presented onscreen are a projection of a particular String; can we use that String as the value internally? - To make this work, we would probably maintain a list of ranges/lengths/index pairs as our "display lines", which we can then
sliceout of the original value. - To avoid the cost of repeated slicing, we would probably want to memoize the values as we go.
- When updates are made, only those slices within or after the update range would need invalidated (probably less?).
- Only lines actually being displayed need
sliced. - Reflow should become faster (since it's now only responsible for recording indices).
- Display should become slower for small values, but faster overall (since slices aren't cut "eagerly", some work gets pushed to render-time, but less in general).
- This is obviously a larger refactoring, but may provide significant net benefit.
- The thought I'm trying to express here is that maybe we don't need to treat the value as a collection of
I'd love to know if any of these options have been explored or rejected previously, or if there's any interest in seeing work in any of these directions.