Plug.kak startup became faster!

Good news for plug.kak users!

Recently, @mralusv added a new command, called plug-chain. It allows chaining plug commands into one long command, that only invokes the shell once. As a result, the startup time is improved. Huge thanks to @mralusv for working on this feature.

I’ll be cutting v2.1.0 release soon, but this is already available on the main repository branch, and I welcome everyone to test this feature, and see if it improves startup time of your configuration. For the reference, here’s my plugin configuration section, altered to use the new plug-chain command: plugins.kak.

7 Likes

Before

hyperfine "kak -ui dummy -e 'quit'"
Benchmark #1: kak -ui dummy -e 'quit'
  Time (mean ± σ):     196.5 ms ±   1.2 ms    [User: 154.6 ms, System: 48.4 ms]
  Range (min … max):   195.1 ms … 198.8 ms    15 runs

After

hyperfine "kak -ui dummy -e 'quit'"
Benchmark #1: kak -ui dummy -e 'quit'
  Time (mean ± σ):     178.6 ms ±   1.3 ms    [User: 142.2 ms, System: 42.3 ms]
  Range (min … max):   176.6 ms … 181.4 ms    16 runs

:+1:

39 plugins: before and after

plug-chain

Thanks guys.

wondering why there’s such drastic differences in startup time…
I have quite a few plugins, but my startup is fast (i’m not using plug.kak though):

Benchmark 1: kak -ui dummy -e quit
  Time (mean ± σ):      35.7 ms ±   1.7 ms    [User: 29.4 ms, System: 10.5 ms]
  Range (min … max):    34.3 ms …  44.4 ms    83 runs

plug.kak does a lot of stuff for you under the hood.

It registers hooks for a more convenient lazy loading, encapsulates plugin configuration and handles errors during startup, and so on. The main startup time cost comes from shell invocations needed to load and set up plugins.

@kkga would you care to share your (sanitized) configs? i’m quite interested in startup cost, because when using kak as the $EDITOR or $GIT_EDITOR, anything above 100ms (or something like that) hits the human persistence of vision threshold and becomes an annoyance. Basically, any visible delay puts humans in a different mood (interactive vs planned). Anyway, theory aside, I’d like to find any remaining bottlenecks in plug.kak (and kak-bundle as well).

Here you go. There’s a bunch of files, but the plugins are defined in kakrc:
https://github.com/kkga/dotfiles/tree/master/.config/kak

@kkga something seems to be missing. You seem to be using another plugin manager, cork (possibly at GitHub - topisani/cork.kak — it doesn’t seem to have been announced over here) but I can’t grep any place where it is actually loaded.

Edit: nevermind, cork is unusual in that it needs cork.sh to be renamed into $PATH as cork, and then it is available as a shell (and %sh) command. There is no kak file defining commands.

Edit 2: I can’t find performance ideas in cork, and I’ve had trouble using it (how to install plugins in the first place?). Each and every cork command spawns bash on top of %sh{}, defines kak commands, and executes them. It is of course possible that you have really fast hardware, so we need to compare comparables. In any case, I can’t reproduce as of now; perhaps there should be another thread for this plugin manager.

I actually only started using cork very recently. I’ve always used git-submodules for handling/updating kakoune plugins and then manually sourced them in kakrc.
Cork does provide some niceties around scoping plugin-related options in config files, so that’s my only reason to use it.

I haven’t noticed any changes in startup performance after switching from manual sourcing to cork (although i haven’t measured it).

I can’t find performance ideas in cork, and I’ve had trouble using it (how to install plugins in the first place?).

Plugins are installed by the same command: cork update, which can be run either inside kakoune or from a shell session. I’m running it as a part of system update with topgrade.

It is of course possible that you have really fast hardware, so we need to compare comparables.

The hyperfine results I shared earlier are done on X1 Carbon gen 9 (i5). I’m getting similar results right now on my desktop machine:

~> inxi --cpu
CPU:       Info: 6-Core model: AMD Ryzen 5 3600 bits: 64 type: MT MCP cache: L2: 3 MiB
           Speed: 2196 MHz min/max: 2200/3600 MHz Core speeds (MHz): 1: 2196 2: 2119 3: 2452 4: 3599 5: 2301 6: 2079 7: 2434
           8: 3951 9: 2198 10: 2199 11: 2438 12: 2061

~> hyperfine 'command kak -ui dummy -e quit'
Benchmark 1: kak -ui dummy -e quit
  Time (mean ± σ):      34.7 ms ±   0.3 ms    [User: 28.8 ms, System: 9.8 ms]
  Range (min … max):    33.8 ms …  35.3 ms    85 runs

UPD: actually there’s one more reason I use cork (over alternatives): it can be run from shell, as I don’t want to manually update plugins from inside Kakoune.

1 Like

wow, cork.kak looks very interesting indeed!