Rubyで書いたスクリプトの起動時間を速くした話。 tl;dr bundle execもしくはbundle install --binstubsで生成して動かす実行ファイルはそこそこ遅い 一方、bundlerには bundle install --standaloneというオプションがあり、実行時にbundler無しにversion lockしたgemを使う方法を提供する仕組みで、bundle install --standalone すると bundle/bundler/setup.rb が生成される。 bundle/bundler/setup.rb にはGemfile.lockに従ったバージョンのgemのlibのパスが$LOAD_PATHにpushされるコードが書かれているので、bundlerに含まれる 'bundle/setup' を require 'bundle/setup'する