-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
IO speed vs grep or ag #696
Comments
Please provide a test case independent of fzf. |
My suspicion is that something else funky is going on here, and that "ripgrep has slow output" is probably neither true nor the cause. On a simple search in a checkout of the Linux kernel, for example, it's not even close:
Note that a similar case made an appearance in my benchmarks:
In this case, Note that the output of running I've also tried comparing the timings when using the Bottom line: we need more data. |
Colors don't appear to be the issue either:
|
If anything, what I'm discovering here is that ag's output is the one that is incredibly slow. If you run |
I will look into this, thanks. I agree that these are curious results! |
To confirm that |
I confirmed that rg is blazing fast when used for feeding FZF in vim, except when color=always. which sort of sucks because the way FZF works in vim does show colors, which is visually helpful. I'm actually unsure of the actual code involved here. FZF is a terminal application and it may be the case that running it in vim brings an entire terminal emulator/PTY layer within Vim into the mix. It is no longer clear at all that the issue is on ripgrep's side. Looking at fzf.vim code, there appears to be a rather lot of stuff "geared toward" ag, not sure if it is responsible for the difference. |
@unphased Yeah basically in order for this to be a problem with ripgrep, I need to see a case that I can reproduce without fzf. I did test ripgrep and ag with colors (see above), but it didn't make any appreciable difference. Thanks for investigating! Please do let me know if you come up with anything! |
yeah I tried fzf a while ago but it tries to do things that are too smart (messing with tmux windows) when run directly from the shell. Lately I have found it tremendously powerful as a replacement for ctrlP in vim, and plus when you invoke it on a fresh system it very helpfully downloads the executable for you. So, I use fzf exclusively in vim now... I will revisit this another day when I really want colors inside fzf, but for the time being nothing beats non-colored rg's speed for feeding fzf |
It is possible that #764 is the culprit here, although I am still perplexed at why I can't reproduce this in a terminal. |
I will create an example base on Vim's async API to confirm this issue. when run rg or grep command, if I want only the first stdout data. grep is much faster than ag/rg etc. |
well, it looks like whatever dependency ripgrep uses causes the colors to be assembled in an almost worst case method where multiple color codes are emitted for every single character. It's a bit like immediate mode OpenGL geometry, it's just absurd overhead, despite technically producing correct results. It totally makes sense to me that we see this effect if the terminals you test on are significantly more efficient at handling the color state changes than vim's builtin terminal emulator is. Two problems afoot: 1) make ripgrep stop producing laughably inefficient ANSI color codes 2) make vim's terminal emulation less inefficient both would be good to have, but either one should go a long way toward improving the perf. |
@unphased This characterization is imprecise. ripgrep emits distinct color codes for every match. If every match is a single character, and every single character is a match (e.g., Knowing this, can anyone reliably reproduce the issue without fzf? Failing that, could someone say something about what ripgrep commands |
It seems that searching for Yes I can accept the argument that ripgrep shouldnt be expected to "resolve" unnecessary color state changes in its output. that would probably be being too smart about things.
^ from my vimrc when the |
@unphased |
It still ends up being unexplainably slow compared to configured for no colors. |
Hmmm that suggests #764 may not be the culprit. :-/ |
Upon testing in Linux, i do not see much of a slowdown at all comparing color to non colored here. But on my 2017 MacBook Pro there is a ~5 or so factor speed difference. Which now I think i would prefer to get the color and live with it being slower. It indexes 4 million lines (my home directory) within a tolerable amount of time. I don't even understand how that is possible, it's like probably on the order of close to a gigabyte of data getting crunched. Looking at htop, when this runs, with |
OK more information. in a linux vm in a macbook (a 2015 model this time) the speed difference is also very present. I did some more tests...
as we expect it seems rg is only marginally slower at producing the output. when i then take these saved outputs to feed to fzf like this:
the additional slowdown is not very noticeable, certainly not ~5x slower. I'm going to look in the vim fzf plugin for its invocation, since it doesnt seem to be that slow using just |
Well i've reproduced the same commands being sent into fzf that vim does..
when i take the ansi flag out (and feed it ansi colored rg output) it is just as fast as when non colored output is fed in (with or without the ansi flag). That indicates to me that the ansi color parsing itself is the bottleneck. again this is more or less what we could have guessed but now i am more confident about it. |
@unphased Excellent investigation! Does this explain why rg is slow but ag is fast when using fzf? |
That is the one thing this doesn’t explain yet and I have to assemble some output that is comparable with which to do that! |
OK heres another more methodical set of data, now, i dont have a way to time how long fzf takes to index the input, but i can eyeball it. working with around 50MB of input (the colors dont bloat the size of input much...
comparing these 4
Which are respectively: 1. rg producing no colors piped to fzf 2. rg producing colors piped to fzf 3. (1) but cached to disk 4. (2) but cached to disk The timing looks like:
From doing the same thing inside my ubuntu 14.04 vm on same machine:
Grain of salt with these times, probably not accurate to more than ~0.25 sec, i did not use a stopwatch. Now I don't know how my factor of 5 changed to a factor of barely 2. There does seem to be a 'caching' aspect to this. running it a second and subsequent times, fzf indexes a good bit faster. |
I did the same procedure with I tested it through fzf inside vim and it is exactly as fast as running fzf independently of vim. At this point it doesn't seem like there are any "issues" to speak of that are left... not using colors is going to make for a snappier result, but it won't be as pleasant to look at and sift through. Them's the breaks. |
fwiw, I have been using |
@unphased I've never used fzf before, so it's hard for me to know whether that's too slow or not. I guess it kind of depends on how other similar tools perform. e.g., Maybe compare |
I still run into this issue, let me know if/how I can help debug any further. |
@Gee19 With #764 fixed, I don't think there are any other obvious problems for this. Could you please write a detailed report of what exactly is happening, preferably in enough detail such that others can reproduce it? Ideally, all inputs and corpora are open so that others can try the exact same procedure. |
I was reading this
junegunn/fzf.vim#488 (comment)
And the last few comments about how ag apparently can output IO 5 times faster than ripgrep stood out. Is that true? If so, are there any plans to speed it up, or is the case described in the issue outside of what you consider normal usage?
The text was updated successfully, but these errors were encountered: