asayers / tass

Like less, but for tabular data
The Unlicense
17 stars 4 forks source link

Redrawing is slow #3

Open dufferzafar opened 2 years ago

dufferzafar commented 2 years ago

Compared to csvlens, tass suffers from redrawing issues. Were just pressing arrow-keys causes very slow redrawing of entire screen.

https://github.com/YS-L/csvlens

asayers commented 2 years ago

Nice, I didn't know about csvlens - thanks! I'll link to it in the README.

Out of interest, do you know how they get away without redrawing the whole screen when you press the arrow keys?

dufferzafar commented 2 years ago

@asayers I just looked at both csvlens & tass's code and at a quick glance, it seems that tass is directly writing content to the screen and is doing it at every arrow key press.

While csvlens is using a higher level library tui to handle the screen drawing, but is only modifying the state at each keypress. The tui library uses crossterm internally, but it can be smarter about the screen painting.

This would be similar to how ncurses works in the refresh method where in it only updates the parts of the screen that actually changed: https://tldp.org/LDP/lpg/node114.html

asayers commented 2 years ago

Thanks for taking the time to investigate!

I can imagine a way you could optimise down-arrow: draw the new row at the bottom, pushing the header off the top of the screen; then jump up the the top, clear the row, and re-draw the header. This would save a lot of IO, and it's the most common action.

For left-arrow, right-arrow, and up-arrow, I can't think of any way it can be optimised beyond "redraw the whole screen".