lf icon indicating copy to clipboard operation
lf copied to clipboard

[Feature request] Preview delay

Open veganomy opened this issue 1 year ago • 4 comments

Can we get preview delay in milliseconds? When I traverse through the directory list (by holding j or k), lf seems to speedrun previews of all directories. This is even worse when it's huge text files and database textual files. My CPU / GPU roars when I do this.

veganomy avatar Nov 01 '24 15:11 veganomy

The best thing I can think of is to add a small sleep in your previewer script.

The way previewing works is that all the files being scrolled through are added to a queue, which is then processed by a separate thread. That thread runs in a while loop, and during each iteration it pops as many items from the queue as possible but only displays the last item, so slowing down that thread should cause more items to be bunched up together and skipped.

joelim-work avatar Nov 02 '24 04:11 joelim-work

@joelim-work I don't have a previewer. It's mainly directory previews & text previews that are not related to previewer at all.
The continuous listing of directories and accessing of text files by themselves is hurting the resources.
My server is an old rasp pi which runs on 1Ghz & an EMMC storage. I mostly never use it. But when I do, even using lf seems to be resource intensive, considering it to be the most lightweight.

That's why lf needs a dedicated preview delay, because lf already does it on directories and text files.

I could disable preview altogether. But that's like not going to school because I fail in exam.

veganomy avatar Nov 02 '24 05:11 veganomy

I had a look at the code - in the case of directories, lf receives a continuous stream of j key events when it is pressed and held, and this ends up launching a separate goroutine to load the corresponding new directory for each key event: https://github.com/gokcehan/lf/blob/dda8e88aafd4ff5370dbfac1b61fb193c329cbd0/nav.go#L498-L506

It looks like this is by design though, perhaps it was done that way so that every directory would get populated into the directory cache (nav.dircache).

joelim-work avatar Nov 02 '24 07:11 joelim-work

That's unfortunate. Currently I'm half jumping (ctrl+d/u) in order to avoid preview bombing. Then I find my needed selection with find (f) & the first charcter.
If there was a delay for previewing, I could've naturally traversing instead of the other way.

veganomy avatar Nov 02 '24 07:11 veganomy