Optimizations for TextView
Only clear the index when the textview dimensions change or the text itself is cleared. Add to the index when new text is added to the view.
Fixes #266
I've created benchmarks for writing to and drawing TextViews (submitted as #356) and compared the results before and after applying these optimizations.
go test -run=NONE -bench=. -count=3
benchcmp -best -changed
So, it has gotten worse? Because after shows more ns/operation and such
Based on the benchmark results, these optimizations:
- Increase the amount of time it takes to write to unwrapped TextViews by 350%
- Do not affect the amount of time it takes to write to wrapped TextViews
- Increase the number of allocations when writing to both unwrapped and wrapped TextViews by 1000%
- Increase the allocation size when writing to unwrapped TextViews by 500%
- Do not affect the allocation size of writing to wrapped TextViews
- Reduce the amount of time it takes to draw unwrapped TextViews by 65%
- Reduce the amount of time it takes to draw wrapped TextViews by 20%
- Reduce the allocation size when drawing unwrapped TextViews by 40%
- Reduce the allocation size when drawing wrapped TextViews by 20%
This change optimizes for large amounts of text, especially one that constantly gets appended to (displaying a tailing log). Your benchmarks present a static text of 512 bytes, where performance is quite insignificant.
Thanks for your feedback. I've updated the tests and benchmarks to include cases where a small amount of data is written to a TextView that contains a lot of data. You can see these changes in the updated pull request I linked earlier.
Any chance to have this merged? I am currently using tview for TUI for my experimental chat application and use TextView as a chat log.
@tslocum, hey, since you are maintaining cview, what do you think about getting that PR in? Imo this is a good improvement. I would submit it but there are some non-trivial conflicts so I am not sure about them.
I rebased it here: https://github.com/foxcpp/tview/tree/textview-opts but as I said, I am not sure if I did everything correctly. Also included my small optimization from #435.
Thanks @foxcpp. I am interested in merging your changes into cview. I'll let you know once I've had a chance to review your changes.
Hey @foxcpp, I only see your optimization to use TrimRightFunc in your updated branches. Were you able to review the benchmark results which seem to show these changes cause decreases in performance?
@tslocum Woops, forgot to git push. Now it should be there. Also added your benchmarks.
Here is the benchcmp output master vs textview-opts branch: benchcmp.txt
There is a decrease in performance for Draw almost everywhere, enough to nullify my TrimRightFunc change, huh. Write gets +500% improvement for scrollable TextView, though.
I believe you have the results backwards: when not wrapping text, Draw is improved 60% while Write is up to 600% slower (if old is master and new is textview-opts).
Woops x2. You are right.
Closing this as it's obsolete. Check out the new TextView implementation for details.