-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Milestone
Description
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 with hyperfine
:
hyperfine \
--warmup 10 \
--export-markdown bat_startup.md \
'bat --no-config --color=always'
On my laptop, this results in:
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
bat --no-config --color=always |
45.3 ± 0.7 | 44.0 | 47.4 | 1.00 |
If we use perf
to get a profile
perf 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:
- Somehow parallelize the deserialization process (maybe by splitting up the binaries into smaller chunks. After all, they are made out of ~100 different syntaxes and themes)
- Only load syntaxes and themes "on demand". If syntaxes and themes were serialized separately, we might be able to load them on demand. It's probably not as easy as it sounds, because syntaxes are interlinked (code blocks in markdown files could require the loading of all kinds of syntaxes, for example).
- Try to look into ways to improve the deserialization speed.
- The assets are currently stored in compressed form. I think I have tried storing them in uncompressed form once (and didn't see any performance improvements), but it might be worth re-evaluating that.
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).
aminya and julius59Neved4 and joshsleeperjoshsleeper