From c50e30c4cb0c50802a5bfb1afc7a81da8cc478b9 Mon Sep 17 00:00:00 2001 From: Jan Krutisch Date: Thu, 2 Nov 2017 15:57:12 +0100 Subject: [PATCH] Bail out of reducing depency trees on huge dependency conflict sets This is a simple fix for #6114, in which sometimes conflict sets get so huge that the current reducing code (which is based on Array#combination) breaks down. By simply bailing out when the conflict set is bigger than a certain size, we'll get a result that is similar to what happened in earlier bundler versions but skip a ton of CPU cycles and memory allocations. I've chosen the limit rather unscientifically by playing around with the result set sizes. 15 seems to be a good compromise but really anything larger than 10 should work (and with work I mean "should not usually not have to be invoked"). --- lib/bundler/resolver.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index f75c6695349..8a3afa34188 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -309,6 +309,8 @@ def version_conflict_message(e) :solver_name => "Bundler", :possibility_type => "gem", :reduce_trees => lambda do |trees| + # bail out if tree size is too big for Array#combination to make any sense + return trees if trees.size > 15 maximal = 1.upto(trees.size).map do |size| trees.map(&:last).flatten(1).combination(size).to_a end.flatten(1).select do |deps|