Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Heh. I write an internal developer tool at Shopify that is (somewhat) conceptually similar to vagrant. (https://twitter.com/burkelibbey/status/858013844626649092)

Like you, we distribute it as a git repo. We don't use bootsnap with it, but we have a few strategies that give us reasonable times:

    $ time ./bin/dev help up >/dev/null
    0.07s user 0.03s system 98% cpu 0.102 total
* We vendor every dependency (and try really hard to avoid them in the first place -- we have 5, only one of which is >5 source files), and prevent loading rubygems. Rubygems takes a long time to load. Our shebang is `/usr/bin/ruby --disable-gems`.

* Autoload everything. Our toplevel lib/dev.rb file is a whole-namespace autoload registry. Only a few other constants are defined there. Everything is loaded just by cascading through autoloads.

* Defer stdlib requires: We load most stdlib features within the method body from which they're used. Several stdlib features take a surprisingly long time to load.



I pulled these requires into the method bodies where they are used:

- openssl

- digest

- resolv

- rgl

- net/ssh

- (internal http client)

- (internal package manager)

Doing this saved about 40% of our CLI boot time:

    $ time /usr/local/bin/airlab > /dev/null
    /usr/local/bin/airlab > /dev/null  0.27s user 0.15s system 79% cpu 0.521 total
    $ git co jake--no-rubygems
    $ time /usr/local/bin/airlab > /dev/null
    /usr/local/bin/airlab > /dev/null  0.24s user 0.08s system 98% cpu 0.326 total


Great tips! We should do the refactor work to switch to lazy-loading everything, but that will take some time. I can certainly get the Rubygems savings today though.


Thanks for the tips! I'm definitely going to use these as well.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: