Code Monkey home page Code Monkey logo

Comments (3)

Tuurlijk avatar Tuurlijk commented on August 18, 2024 3

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?

from zgen.

smac89 avatar smac89 commented on August 18, 2024

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

🤕

I could do with more time saving, but this is a start

from zgen.

jandamm avatar jandamm commented on August 18, 2024

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.

from zgen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.