visidata icon indicating copy to clipboard operation
visidata copied to clipboard

[mainloop-] during replay, redraw less often

Open midichef opened this issue 3 months ago • 0 comments

When replaying commands, visidata 3.0 versions are noticeably slower to load some large sheets than v2.11 was. It's caused by redrawing the screen too often. The symptom to look for is that the progress (% loading…) is updated dozens of times per second.

Sometimes the quick updates are steady. For other files they come and go in short bursts, then doing proper slower updating for longer stretches. Only the short bursts of quick updates will cause slower loading.

Here is a case that, on my system, consistently exhibits the problem.

seq 2000111 > 2m.tsv
# interactive mode:  quit.vdj is a timing helper script that opens 2m.tsv and immediately quits
=time vd -p quit.vdj
6.63user

After applying 02432ff86ec91c36ed53c507319402d7d7c054b0:

=time vd.fixed -p quit.vdj
5.12user

quit.vdj.txt

In this case the bug causes 30% slower loading. It causes the screen to be drawn 37 times per second, vs the fixed version that draws 7 times per second.

While I was patching mainloop, I also fixed an off-by-one error in counting idle timeouts (51421d9a3afb211a1cc820fffc2bd1b6dd09643a). The effect will be ~9% fewer recalculations of columns when idling. To demonstrate the change: echo a |vd then make an ExprColumn: =vd.status('test'). For each row in the column, the ExprColumn will be calculated once, and then recalculated once after every timeout. Before the fix, in v3.0.2 it will output 12 lines to the status bar, and after the fix, only 11.

--

Edited to add: it turns out this PR also closes #2274. In that bug, editCell queues commands in _nextCommands, triggering the same high rate of redrawing.

midichef avatar Apr 03 '24 05:04 midichef