diff options
author | Tim Smith <tsmith84@gmail.com> | 2021-12-25 21:21:02 -0800 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2021-12-25 21:21:02 -0800 |
commit | 1bf995b32c5a049e9b55c08e7434419a586aa190 (patch) | |
tree | 6a783459d0e16b62ae7be8a2df0f9b96976058cb | |
parent | 50a0001bae754c66feb69c84b64cb305a03a34d2 (diff) | |
download | chef-faster_knife.tar.gz |
Reduce 213 requires from each knife callfaster_knife
Right now for terrible reasons knife bootstrap gets initialized during every knife command due to sadness in knife-cloud. That wouldn't be nearly as bad if we were a bit more lazy in the bootstrap plugin.
1. JSON compat is actually used in the options so it needs to be required outside deps method. This works right now because we're not lazy all over the place and this thing gets loaded in 20 places
2. Net::SSH doesn't even appear to be used here. This plugin is all train now so we shouldn't have to require that.
3. Erubis should only get called when we're rendering out the template
Before:
```
There were 642 requires
The total time spend requiring was: 1.167499999748543
```
After
```
There were 429 requires
The total time spend requiring was: 0.6953230001963675
```
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | knife/lib/chef/knife/bootstrap.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/knife/lib/chef/knife/bootstrap.rb b/knife/lib/chef/knife/bootstrap.rb index 8909abd45b..e2b9993e60 100644 --- a/knife/lib/chef/knife/bootstrap.rb +++ b/knife/lib/chef/knife/bootstrap.rb @@ -20,6 +20,7 @@ require_relative "../knife" require_relative "data_bag_secret_options" require "chef-utils/dist" unless defined?(ChefUtils::Dist) require "license_acceptance/cli_flags/mixlib_cli" +require "chef/json_compat" unless defined?(Chef::JSONCompat) # can't be lazy loaded since it's used in options module LicenseAcceptance autoload :Acceptor, "license_acceptance/acceptor" @@ -416,9 +417,6 @@ class Chef attr_reader :connection deps do - require "erubis" unless defined?(Erubis) - require "net/ssh" unless defined?(Net::SSH) - require "chef/json_compat" unless defined?(Chef::JSONCompat) require "chef-config/path_helper" unless defined?(ChefConfig::PathHelper) require_relative "bootstrap/chef_vault_handler" require_relative "bootstrap/client_builder" @@ -544,6 +542,7 @@ class Chef end def render_template + require "erubis" unless defined?(Erubis) @config[:first_boot_attributes] = first_boot_attributes template_file = find_template template = IO.read(template_file).chomp |