diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-08-12 14:15:45 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-08-12 14:15:45 -0700 |
commit | 904a32331073b5840eb2742d5178d7ca58d91f97 (patch) | |
tree | 0c07857ce2544de5cc120e0a5cae9073215f9839 | |
parent | 5cdffd971171b2d550b583ee48149435dc3d0ba1 (diff) | |
download | mixlib-config-904a32331073b5840eb2742d5178d7ca58d91f97.tar.gz |
Optimize requires for non-omnibus installsrequires
require is quite slow in Ruby and doing requires for things you've already required is also slow. We've used this simple hack in Chef to speed up our requires. In the omnibus installs we patch how rubygems works to make this somewhat pointless, but this will help non-omnibus installs
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/mixlib/config.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/mixlib/config.rb b/lib/mixlib/config.rb index d57a44a..1508f5b 100644 --- a/lib/mixlib/config.rb +++ b/lib/mixlib/config.rb @@ -69,7 +69,7 @@ module Mixlib # === Parameters # filename<String>:: A filename to read from def from_yaml(filename) - require "yaml" + require "yaml" unless defined?(YAML) from_hash(YAML.load(IO.read(filename))) end @@ -78,12 +78,12 @@ module Mixlib # === Parameters # filename<String>:: A filename to read from def from_json(filename) - require "json" + require "json" unless defined?(JSON) from_hash(JSON.parse(IO.read(filename))) end def from_toml(filename) - require "tomlrb" + require "tomlrb" unless defined?(Tomlrb) from_hash(Tomlrb.parse(IO.read(filename), symbolize_keys: true)) end |