From c380aac19d097f1d38d2299fe3f64567b42fb55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 13 May 2022 11:26:20 +0200 Subject: [PATCH] [rubygems/rubygems] Improve `bundler/setup` performance again On a different patch, it was noticed Ngam Pham that we are calling `LazySpecification#hash` many times, and simply memoizing that led to a very considerable performance improvement in his app. I noticed though that we shouldn't be calling `LazySpecification#hash` that many times, and I located the culprit at `SpecSet#for` where we were deduplicating the partial aggregated result on every iteration. It is enough to do it just once at the end. This leads on a 12% speedup on Rails repository Gemfile vs the previous 8% I was getting from memoizing `LazySpecification#hash`. Also, after this patch memoizing `LazySpecification#hash` has no effect in performance anymore. https://github.com/rubygems/rubygems/commit/68d00a9edd Co-authored-by: Ngan Pham --- lib/bundler/spec_set.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index a19d18388a..dc55e5eaed 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -24,7 +24,7 @@ module Bundler specs_for_dep = spec_for_dependency(dep, match_current_platform) if specs_for_dep.any? - match_current_platform ? specs += specs_for_dep : specs |= specs_for_dep + specs += specs_for_dep specs_for_dep.first.dependencies.each do |d| next if d.type == :development @@ -40,6 +40,8 @@ module Bundler specs << spec end + specs.uniq! unless match_current_platform + check ? true : specs end