Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve zf’s speed #46

Open
Brixy opened this issue Jul 22, 2023 · 5 comments
Open

Improve zf’s speed #46

Brixy opened this issue Jul 22, 2023 · 5 comments

Comments

@Brixy
Copy link

Brixy commented Jul 22, 2023

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:

  • time find -type f | zf: 2.29 secs (~300,000 files)

  • time find -type f | fzf: 170.00 millis (~300,000 files)

  • time fd -t f | zf: 1.84 secs (~128,000 files)

  • time fd -t f | fzf: 725.22 millis (~128,000 files)

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
Copy link
Owner

Hi @Brixy! I think this is closely related to #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 (8ddc8fd) 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
Copy link
Author

Brixy commented Jul 22, 2023

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
Copy link
Owner

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
Copy link
Author

Brixy commented Jul 24, 2023

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:

  • time find . -type f 2> /dev/null | fzf`: 212.54 millis (incl. the time required to read from stdin; ~270,000 files)
  • time find . -type f 2> /dev/null | zf`: 2.90 secs

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
Copy link
Owner

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 #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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants