natecraddock / zf

a commandline fuzzy finder and zig package designed for filtering filepaths
MIT License
451 stars 14 forks source link

Improve zf’s speed #46

Open Brixy opened 1 year ago

Brixy commented 1 year ago

Dear Nathan,

thank you very much for this excellent tool. I would like to switch to zf from fzf.

As fzf feels faster and snappier, I did some very basic benchmark testing. Here’s the results:

Can/will this be adressed?

Thank you very much.

Background:

Tested with zf 0.8.0 on Void Linux with fish shell. (Experienced some problems building zf from source as I am just slowly digging into zig.)

Also tested with -k -p flags.

I always work from ~/. That’s why I always search many files. This is what I have been using for years within a little POSIX script: fd --type file --max-depth 1 && fd --type file --min-depth 2 | fzf.

natecraddock commented 1 year ago

Hi @Brixy! I think this is closely related to https://github.com/natecraddock/zf/issues/38

What you are seeing here is zf blocks until all of stdin has been read, while fzf immediately shows the UI and incrementally reads from stdin.

Until recently (https://github.com/natecraddock/zf/commit/8ddc8fdb3ddee08a4026acbfe494321d828ab16c) zf didn't have an easy way to read stdin in increments like fzf. But now that I added an event loop this is solvable.

So this issue is on my radar. I'm not sure when I'll add it, but it is something I plan to fix.

Just to double check, you aren't experiencing zf itself being slow after it loads right?

Brixy commented 1 year ago

Hi!

Thanks for your response.

My impression is that this could be zf related. The times mentioned for fzf are fzf’s startup time + fd/find search, that is the times for time fd -t f and time fd -t f | fzf are almost identical.

time fd -t f | zf is notably slower. But honestly: It’s not a big problem. I only noticed it because of the large number of files I usually search, starting from $HOME as mentioned. Really love the simplicity and excellent search results of your tool and will use it in any case.

Just to double check, you aren't experiencing zf itself being slow after it loads right?

After zf has loaded it is very fast and responsive.

Thank you!

natecraddock commented 1 year ago

I think we are on the same page, but I'm going to share this just to make sure

Kapture 2023-07-23 at 13 05 30

In the bottom left of fzf it shows a counter increasing as it reads the lines from stdin. The difference between zf and fzf is that zf doesn't display the UI until all lines are loaded, but fzf allows using the UI while the lines are read. So in my experience fzf and zf take roughly the same amount of time to read all the lines, but fzf has a UI open faster

I'm planning on changing zf to match fzf's behavior here.

Really love the simplicity and excellent search results of your tool and will use it in any case.

Happy to hear this! Thank you for the kind words

Brixy commented 1 year ago

Yes, I get what you mean. (Sorry if I am not precise enough. English is not my mother tongue.)

For my setup loading fzf plus fzf’s reading from stdin takes about 200 milliseconds, that includes the time the counter needs to finish.

So in my experience fzf and zf take roughly the same amount of time to read all the lines, but fzf has a UI open faster

I have suspected that because you asked back 😀. In my case zf takes a lot longer to load which is surprising because the actual search is done by e.g. find or fd. #38 will definitely be an improvement, but my impression is that ‘my’ issue and #38 are not be related.

As a precaution I just used the find command from your .gif file:

I’ll try to compile zf from the current branch or wait for a new release and give feedback then.

Thanks for your work and patience!

natecraddock commented 1 year ago

Sorry if I am not precise enough. English is not my mother tongue

Your English is great! I couldn't tell :)

but my impression is that ‘my’ issue and https://github.com/natecraddock/zf/issues/38 are not be related.

I'm glad I asked more. This is strange, because all zf is doing is splitting the input on \n bytes. I'll take a look into this...

I’ll try to compile zf from the current branch or wait for a new release and give feedback then.

Nothing meaningful for reading from stdin has changed since 0.8.0, so you shouldn't need to try a different version. Also zf master isn't super stable at the moment as I add some new features ...