-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a bootsnap command to allow to precompile gems without booting the application #326
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea 👍
cb62720
to
e26dd90
Compare
class CLI | ||
unless Regexp.method_defined?(:match?) | ||
module RegexpMatchBackport | ||
refine Regepx do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's just a CLI and the process is thrown away, it might be enough to define the method directly? Or is the code actually loaded? I thought it was just parsed and the iseq cached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather avoid doing it. I'll likely add some tests for that class, so it's better if it doesn't monkey patch Regexp.
lib/bootsnap/cli.rb
Outdated
|
||
source.map { |d| File.expand_path(d) }.each do |path| | ||
Dir[File.join(path, '**/*.rb')].each do |ruby_file| | ||
if !exclude || !exclude.match?(ruby_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even just use =~
which does not allocate a MatchData if that's what we're going for.
def invalid_usage!(message) | ||
STDERR.puts message | ||
STDERR.puts | ||
STDERR.puts parser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe warn
would be simpler?
lib/bootsnap/cli.rb
Outdated
sources += $LOAD_PATH | ||
end | ||
|
||
CompileCache::ISeq.compile_option_updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure it's worth changing the API or adding an alias, but this name could be clearer, now that it's called from outside of CompileCache::ISeq
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I think I'll refactor this so that I don't need this to be used.
So after trying this on one of our mid sized apps, I made a few changes. I added I also realized that I'll add some tests and some documentation tomorrow and likely will cut a new release. |
46b10f5
to
f9e74de
Compare
f9e74de
to
25d0bd7
Compare
Hum, it's been hours and the travis builds still didn't start. We should migrate to GitHub Actions soon. |
In normal usage, bootsnap's iseq cache is computed on the fly as the ruby files are required.
Which means that if you want to precompute the cache, the only way is to boot the application.
In my case I'm building Docker image for ruby applications, and I'm caching all the gems in a content addressed layer. So I would like to be able to precompile the gems iseq cache without having to have a bootable application, so that the bootsnap cache is part of the bundler layer.
This is exactly what this new executable allows, it setup bundler to get all the relevant gems in
$LOAD_PATH
, and then precompile all the requirable.