From 1bf995b32c5a049e9b55c08e7434419a586aa190 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sat, 25 Dec 2021 21:21:02 -0800 Subject: Reduce 213 requires from each knife call 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 --- knife/lib/chef/knife/bootstrap.rb | 5 ++--- 1 file 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 -- cgit v1.2.1