gokcehan / lf

Terminal file manager
MIT License
7.79k stars 331 forks source link

fix: optimize speed of retrieving user/group widths #1800

Closed owallb closed 2 months ago

owallb commented 2 months ago

After using the new user and group info parameters for a while I have started to notice an occasional slow-down, when quickly navigating down/up in the same directory.

I investigated the time it would take retrieve user and group max widths, where total is the whole getInfo loop:

Unoptimized, average over N=58, time in ms: getUserWidth getGroupWidth Total
0.01 15.59 15.62
Optimized, average over N=80, time in ms: getUserGroup Total
0.01 0.03

I'm not really sure why getGroupWidth was so slow.

15 ms is not slow enough that I would notice it, what I experienced was that the UI would freeze for about 1 second. But it's probably related to the cause of it.

owallb commented 2 months ago

I made a mistake and didn't call groupName for retrieving the group name. Now that I fixed it, the original issue still remains, which is that calling groupName will sometimes be very slow. I will close this and continue to investigate a different solution.

owallb commented 2 months ago

For future reference, the issue was that I had built with CGO_ENABLED=1. Instead building with CGO_ENABLED=0 fixed the random freezes. It seems the cgo implementation of LookupGroupId in os/user is slow for whatever reason.