Open neumachen opened 7 years ago
I've been shaving microseconds the last couple of days. And I have found that replacing zgen with a shim function saves time:
# Load zgen only if a user types a zgen command
zgen () {
if [[ ! -s ${ZDOTDIR:-${HOME}}/.zgen/zgen.zsh ]]; then
git clone --recursive https://github.com/tarjoilija/zgen.git ${ZDOTDIR:-${HOME}}/.zgen
fi
source ${ZDOTDIR:-${HOME}}/.zgen/zgen.zsh
zgen "$@"
}
Then in your init check script, you can use:
# check if there's no init script
if [[ ! -s ${ZDOTDIR:-${HOME}}/.zgen/init.zsh ]]; then
echo "Creating a zgen save"
else
source ${ZDOTDIR:-${HOME}}/.zgen/init.zsh
fi
And maybe you want to do:
zcompile ${ZDOTDIR:-${HOME}}/.zgen/init.zsh
After generating the init script. Right after zgen save
.
This gives me:
Using zgen
repeat 10 {time zsh -i -c exit}
zsh -i -c exit 0.09s user 0.03s system 98% cpu 0.124 total
zsh -i -c exit 0.09s user 0.03s system 97% cpu 0.118 total
zsh -i -c exit 0.09s user 0.03s system 97% cpu 0.126 total
zsh -i -c exit 0.08s user 0.03s system 98% cpu 0.110 total
zsh -i -c exit 0.08s user 0.03s system 98% cpu 0.117 total
zsh -i -c exit 0.08s user 0.03s system 98% cpu 0.117 total
zsh -i -c exit 0.10s user 0.03s system 98% cpu 0.130 total
zsh -i -c exit 0.09s user 0.03s system 98% cpu 0.122 total
zsh -i -c exit 0.08s user 0.03s system 98% cpu 0.111 total
zsh -i -c exit 0.08s user 0.03s system 98% cpu 0.111 total
Using shim and direct test against and sourcing of init.zsh
repeat 10 {time zsh -i -c exit}
zsh -i -c exit 0.05s user 0.02s system 96% cpu 0.068 total
zsh -i -c exit 0.05s user 0.02s system 97% cpu 0.073 total
zsh -i -c exit 0.05s user 0.02s system 95% cpu 0.072 total
zsh -i -c exit 0.05s user 0.02s system 96% cpu 0.068 total
zsh -i -c exit 0.05s user 0.02s system 96% cpu 0.072 total
zsh -i -c exit 0.05s user 0.02s system 96% cpu 0.071 total
zsh -i -c exit 0.05s user 0.02s system 97% cpu 0.070 total
zsh -i -c exit 0.05s user 0.02s system 96% cpu 0.076 total
zsh -i -c exit 0.05s user 0.02s system 97% cpu 0.068 total
zsh -i -c exit 0.05s user 0.02s system 97% cpu 0.073 total
Does something like that improve loading times for you?
Ironically, not saving the configuration is faster than saving it.
With saving
➜ for i in {1..5}; do /usr/bin/time zsh -i -c exit; done
1.62user 0.28system 0:01.86elapsed 102%CPU (0avgtext+0avgdata 36988maxresident)k
0inputs+48outputs (0major+111549minor)pagefaults 0swaps
1.59user 0.33system 0:01.86elapsed 103%CPU (0avgtext+0avgdata 36936maxresident)k
0inputs+48outputs (0major+111176minor)pagefaults 0swaps
1.59user 0.33system 0:01.87elapsed 102%CPU (0avgtext+0avgdata 37436maxresident)k
0inputs+48outputs (0major+111984minor)pagefaults 0swaps
1.59user 0.32system 0:01.84elapsed 103%CPU (0avgtext+0avgdata 37096maxresident)k
0inputs+48outputs (0major+111236minor)pagefaults 0swaps
1.62user 0.30system 0:01.87elapsed 103%CPU (0avgtext+0avgdata 36984maxresident)k
0inputs+48outputs (0major+111390minor)pagefaults 0swaps
Without saving:
➜ for i in {1..5}; do /usr/bin/time zsh -i -c exit; done
1.45user 0.29system 0:01.75elapsed 99%CPU (0avgtext+0avgdata 33328maxresident)k
0inputs+64outputs (0major+81763minor)pagefaults 0swaps
1.35user 0.25system 0:01.60elapsed 100%CPU (0avgtext+0avgdata 33368maxresident)k
0inputs+64outputs (0major+81667minor)pagefaults 0swaps
1.33user 0.27system 0:01.60elapsed 100%CPU (0avgtext+0avgdata 33280maxresident)k
0inputs+64outputs (0major+81729minor)pagefaults 0swaps
1.39user 0.30system 0:01.69elapsed 100%CPU (0avgtext+0avgdata 33340maxresident)k
0inputs+64outputs (0major+81740minor)pagefaults 0swaps
1.36user 0.27system 0:01.62elapsed 100%CPU (0avgtext+0avgdata 33408maxresident)k
0inputs+64outputs (0major+81695minor)pagefaults 0swaps
:face_with_head_bandage:
I could do with more time saving, but this is a start
I've created a maintained fork of zgen - dubbed zgenom - which fixes some bugs as well as introducing new features like lazy loading and compiling the source files which should improve this issue.
It's really slow loading a new shell with this.
Here's a zprof:
And here's my zgen setup