-
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
Getting 2x boot times using bootsnap #68
Comments
The output from
|
Weird, that's pretty close to what I'm running on, so it must be some other environmental factor. If you're using the require 'bootsnap'
Bootsnap.setup(
cache_dir: 'tmp/cache',
development_mode: true,
disable_trace: false,
load_path_cache: false,
autoload_paths_cache: false,
compile_cache_iseq: false,
compile_cache_yaml: false
) This should disable all features, and should make your boot time consistently similar to the time without bootsnap. Then try toggling on the Then do the same for the Once you've identified which pair of features is making it slower, see if you can isolate it to an individual one of them, or if it's both of them. |
ok, reporting some results: with all features disabled:
load_path_cache: true, autoload_paths_cache: false
load_path_cache: true, autoload_paths_cache: true
compile_cache_iseq: true, compile_cache_yaml: false
compile_cache_iseq: false, compile_cache_yaml: true
Now, the best combination that I've found is enabling everything except
|
This confirm that |
Can you replace require 'bootsnap/bootsnap'
require 'zlib'
module Bootsnap
module CompileCache
module ISeq
class << self
attr_accessor :cache_dir
end
$counts = { i2s: 0, s2o: 0, i2o: 0, uncompilable: 0 }
at_exit { puts $counts.inspect }
def self.input_to_storage(_, path)
$counts[:i2s] += 1
RubyVM::InstructionSequence.compile_file(path).to_binary
rescue SyntaxError
$counts[:uncompilable] += 1
raise Uncompilable, 'syntax error'
end
def self.storage_to_output(binary)
$counts[:s2o] += 1
RubyVM::InstructionSequence.load_from_binary(binary)
rescue RuntimeError => e
if e.message == 'broken binary format'
STDERR.puts "[Bootsnap::CompileCache] warning: rejecting broken binary"
return nil
else
raise
end
end
def self.input_to_output(_)
$counts[:i2o] += 1
nil # ruby handles this
end
module InstructionSequenceMixin
def load_iseq(path)
# Having coverage enabled prevents iseq dumping/loading.
return nil if defined?(Coverage) && Bootsnap::CompileCache::Native.coverage_running?
Bootsnap::CompileCache::Native.fetch(
Bootsnap::CompileCache::ISeq.cache_dir,
path.to_s,
Bootsnap::CompileCache::ISeq
)
rescue RuntimeError => e
if e.message =~ /unmatched platform/
puts "unmatched platform for file #{path}"
end
raise
end
def compile_option=(hash)
super(hash)
Bootsnap::CompileCache::ISeq.compile_option_updated
end
end
def self.compile_option_updated
option = RubyVM::InstructionSequence.compile_option
crc = Zlib.crc32(option.inspect)
Bootsnap::CompileCache::Native.compile_option_crc32 = crc
end
def self.install!(cache_dir)
Bootsnap::CompileCache::ISeq.cache_dir = cache_dir
Bootsnap::CompileCache::ISeq.compile_option_updated
class << RubyVM::InstructionSequence
prepend InstructionSequenceMixin
end
end
end
end
end |
This is the output replacing the code:
|
Huh, ok, can you change the definition of $t = 0
at_exit { puts $t }
def self.storage_to_output(binary)
$counts[:s2o] += 1
t=Time.now
b = RubyVM::InstructionSequence.load_from_binary(binary)
$t += (Time.now - t)
b
rescue RuntimeError => e
if e.message == 'broken binary format'
STDERR.puts "[Bootsnap::CompileCache] warning: rejecting broken binary"
return nil
else
raise
end
end |
ok, running the app a couple of times I got this: during first run after of deleting cache:
during subsequent runs:
|
Oh wow, I wonder where that time is going then. Bizarre. |
Hey, thanks for Bootsnap! I've also just tried it out today and experienced a similar issue - |
Yeah. I just experienced this at Shopify too. I'll try to isolate the cause but I believe |
Something I was pondering the other day is that maybe it is related to sharing the host's filesystem with the Docker container. I was trying this on Mac, and I know there is extra overhead on that platform. Might try to run some experiments when I get a chance. |
Yeah, we could probably document this better, but I would expect performance weirdness when mounting the cache FS over the network, since it would just double the number of network roundtrips. If time-to-access latency is the dominating concern, that would slow it down for sure. |
Importing from rails/rails#29313
Not sure what can I be doing wrong but adding bootsnap to my app doubles the loading time:
Without bootsnap:
With bootsnap:
I've tested this a dozen times getting similar numbers every time.
The text was updated successfully, but these errors were encountered: