Skip to content

Commit

Permalink
Improve inventory target name resolution performance
Browse files Browse the repository at this point in the history
When resolving a large number of targets from a plan the
match_wildcard? regex is compiled on the fly possibly
hundreds or thousands (for a large inventory) of times
per target name resolution.

Switching to File.fnmatch provides a significant speed
increase and seems to more accurately reflect the
functionality stated in the Bolt documentation with
regards to target matching.
  • Loading branch information
seanmil committed Apr 2, 2024
1 parent 4b30c39 commit 95742a8
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/bolt/inventory/inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def match_wildcard?(wildcard, target_name, ext_glob: false)
if ext_glob
File.fnmatch(wildcard, target_name, File::FNM_CASEFOLD | File::FNM_EXTGLOB)
else
regexp = Regexp.new("^#{Regexp.escape(wildcard).gsub('\*', '.*?')}$", Regexp::IGNORECASE)
target_name =~ regexp
File.fnmatch(wildcard, target_name, File::FNM_CASEFOLD)
end
end

Expand Down

0 comments on commit 95742a8

Please sign in to comment.