Add bootsnap for bootup performance #17809
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds caching to Ruby's load path to improve the bootup performance of msfconsole on startup on macOS from ~13 seconds to ~9.7 seconds
Context
I noticed when running
strace
to dump out the Linux system calls on msfconsole bootup, that when msfconsole attempts to load a Ruby file such as withrequire 'foo'
you can see Ruby attempting to find the source code on disk in multiple places:Kali example:
Specifically Ruby is checking the global
$LOAD_PATH
array which tracks the location of all the loaded gems/libraries that Metasploit depends on to find the required Ruby file. Since Metasploit's $LOAD_PATH is pretty big from the amount of gems we have, attempting to load a single Ruby file involves a lot of expensive trial and error until it finds the right file on disk:Example values of $LOAD_PATH
Bootsnap can be used to optimize this look up by performing Path Pre-Scanning - i.e.
Kernel#require
andKernel#load
are modified to eliminate $LOAD_PATH scansVerification
$LOAD_PATH
hack here:metasploit-framework/lib/msf/ui/console/driver.rb
Lines 661 to 675 in 192af21
bundle exec ruby ./msfconsole -q --real-readline
andbundle exec ruby ./msfconsole -q --no-readline
appear to work as expected