-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Moving to the end of 6 Mb file takes forever #304
Comments
Thank you for reporting this. Yes, this is the right place to ask questions like this 👍 Let's try to untangle this a little bit: When you call Next, we can do some benchmarks. I am going to use my hyperfine tool to perform the measurements. First, let's compare
So even with Next, we can make
With everything enabled (decorations such as the line numbers, the grid and ANSI colors), However, this still doesn't quite explain why it takes around 8-10 seconds (on my machine) for the pager to scroll to the end of the output when just using To simulate this behavior in the benchmarks, we can use the
We can see that both So if my interpretation is correct, most of the time (around 75%) is actually caused by the terminal emulator or pager that needs to interpret the output of That being said, we also saw that performance is not I don't see this as a really big problem as I usually don't want to syntax-highlight files with 6 MB of contents, but it might still be fun to work on optimization here. |
Thank you very much @sharkdp for the explanation :) |
@sharkdp would it be possible to have a mode where syntax highlighting is only attempted for the visible region of the text, not for the whole file? assuming that is doable, it would make the performance on large files a lot faster and that would let me view log files with bat and keep bat as an alias for less. |
@gsar I don't think that this is possible.
|
Is there a reason that there is no output buffering? The --help section states that "-u" for unbuffered is ignored since everything is always unbuffered. To test the speed without testing the terminal, I use the following function: Without buffering, this takes 4.4 seconds on my laptop
Without the tail pipe, I can also test the pager speed by quickly pressing ">", then "q" to scroll to the end and then quit (since the scroll to the end takes so long here, the speed should be more ore less accurate) The current version takes ~9 seconds. My proposal would be to implement "-u" command line option and use buffered output if not specified. |
@georgmu That sounds interesting, thank you! Would the buffering cause any observable effects? If not, would you be interested in opening a PR? |
I will prepare a PR, but I am currently fighting the borrow checker to have |
Great, thank you. Let us know if you need help (perhaps just open a PR with the failing version). |
Sorry for the delay. I have managed to build it and then compared bat to cat. cat has a special implementation which reads in bigger blocks, but checks with some special handling to only buffer if there is input available. As an example: If I just open cat and start to type and press return, the line is printed (as expected). With my patch, this is not the case, so the behavior differs. To make it better, the output should always be buffered, but only be flushed if there is no input pending. I will create a PR so you can have a look at the changes |
Draft PR is #596. |
Yes, that's definitely a behavior that should be preserved. Otherwise, we cannot do things like in this (I guess you did that already, but: make sure that you turn off paging if you perform experiments with this: |
You could just do like vim: it will only look a certain number of lines (maybe 500-1000, I don't know) before the view. But, that might require having a pager built in bat for that to work. |
See recent benchmark results in #2244 (comment) |
It seems like there is still room for some easy improvement regarding speed of very large files. |
I am not really sure if this is an issue or intended behaviour.
It took me forever to move to end of a 6Mb file.
Steps to reproduce:
$ seq 1 1000000 > test
$ bat test
Press
G
to move to end of the file.This step took a long time. It seems
bat
was going through the file sequentially.Apologies, if this is not the place to ask this question or this is a known bug/feature.
The text was updated successfully, but these errors were encountered: