-
-
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
Improve bat startup speed #951
Comments
Adding some profiling data from MacOS Mojave (with a SSD): Note: The numbers are going to be off (i.e. about 2x worse) due to the added overhead from running a profiler. Build: It looks like around 31% of the time spent starting up was loading the executable image and initializing it (on MacOS), and around 63% of the total time (95% of Meanwhile (based on the disk usage graph), only 2 milliseconds were spent paging in the executable. I'm also inclined to say that the size of the executable/time spent paging isn't too much of an issue for us currently. 2 milliseconds loading the serialized asset data is significantly less than the 108 milliseconds spent deserializing it. Additional things to note: |
I have made some progress on improving bat startup time through some prototyping work, and I would like to share that prototype here. I would love to get some feedback on it. Especially critisism! The code for the prototype is here: https://github.com/Enselic/bat/compare/6ef2bb3283e1ba5f41316...Enselic:startup-speed-prototype-v1?expand=1 First, allow me to present some performance numbers from my (low-end) machine:
One major limitation of the prototype is that I only made it work for
It should be pretty straightforward to make it work for e.g. file extensions We can see from the benchmark that small syntaxes such sa Zig, which only contains the Zig Syntax Definition, is pretty fast. Medium sized SyntaxSet such as XML (contains Some notable positive properties of the prototype:
Some notable negative properties:
So, how does the prototype work? Roughly like this:
(I realize I should write a lot more details of how it works, but I unfortunately don't have the time for that right now. The code is there for anyone to poke around with though :)) My current plan forward is to take the code from the prototype and turn it into several small and independent PRs that are easy to review and understand one by one, to the extent that is possible and makes sense. |
Since we only modify `pub(crate)` items, the stable bat-as-a-library API is not affected. This takes us one step closer to making SyntaxSet lazy-loaded, which in turn takes us one step closer to solving sharkdp#951.
Since we only modify `pub(crate)` items, the stable bat-as-a-library API is not affected. This takes us one step closer to making SyntaxSet lazy-loaded, which in turn takes us one step closer to solving #951.
Just wanted to elaborate a bit on the next steps I intend to take on the prototype. I will keep updating this comment. I plan on doing the following sequential steps:
|
This is for sharkdp#951. Syntax lazy-loading will come later and have a much bigger impact, but lazy-loading of themes does not have negligible impact.
This is for #951. Syntax lazy-loading will come later and have a much bigger impact, but lazy-loading of themes does not have negligible impact.
Closes sharkdp#915 Closes sharkdp#951 Closes sharkdp#1846 Closes sharkdp#1854
The startup speed of
bat
is currently (v0.15) around 50 ms, which is on (or even past) the edge of being noticeable by humans.It would be great if this situation could be improved.
The startup speed of
bat
can be measured withhyperfine
:hyperfine \ --warmup 10 \ --export-markdown bat_startup.md \ 'bat --no-config --color=always'
On my laptop, this results in:
bat --no-config --color=always
If we use
perf
to get a profileperf record --call-graph dwarf bat --no-config --color=always < /dev/null
we can see that most of the time is spent deserializing the stored syntaxes and themes via
bat::assets::assets_from_cache_or_binary
.There are several ideas that come to mind which could improve the situation:
We should also validate that we are indeed CPU bound here. The
bat
binary is quite large, due to the fact that all syntaxes and themes are included within the binary. It might take some time to simply load that from disk (or cache).The text was updated successfully, but these errors were encountered: