From dfaaada8b6cf09fde47810c9dff79b8165b07ca0 Mon Sep 17 00:00:00 2001 From: richiethomas Date: Fri, 13 Oct 2017 19:33:45 -0400 Subject: Memoize recursive dependency checks; reduces calls to 'f.recursive_dependencies' by an order of magnitude --- Library/Homebrew/cmd/uses.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 0b09e1bf1..5b6319cdc 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -54,11 +54,14 @@ module Homebrew end ignores << "recommended?" if ARGV.include? "--skip-recommended" + memo = {} uses = formulae.select do |f| used_formulae.all? do |ff| begin if recursive deps = f.recursive_dependencies do |dependent, dep| + memo_key = [dependent, dep].to_s + next if memo[memo_key] if dep.recommended? Dependency.prune if ignores.include?("recommended?") || dependent.build.without?(dep) elsif dep.optional? @@ -72,6 +75,7 @@ module Homebrew if dep.is_a?(TapDependency) && !dep.tap.installed? Dependency.keep_but_prune_recursive_deps end + memo[memo_key] = true end dep_formulae = deps.flat_map do |dep| -- cgit v1.2.3