Skip to content

Comments

Don't check whether a plugin needs to be installed:#9328

Merged
colby-swandale merged 1 commit intoruby:masterfrom
Shopify:ec-plugins-no-check
Feb 20, 2026
Merged

Don't check whether a plugin needs to be installed:#9328
colby-swandale merged 1 commit intoruby:masterfrom
Shopify:ec-plugins-no-check

Conversation

@Edouard-chin
Copy link
Contributor

Problem

When Bundler installs gems, it checks whether a gem plugin needs to be installed. This check (Dir.glob) is expensive and is a hotspot when profiling Bundler.

image

Details

Bundler makes a check to see if a gemspec stub exists for the gem being installed. If a gemspec stub already exists and its version is the same as the gem being installed, then Bundler assumes that the gem plugin was already generated in the past and there is no need to generate it again. This check was added for performance purpose but it's counter productive and has the opposite effect.

The vast majority of gems don't have a plugin and we are incurring the cost of doing a Dir.glob for every gems to account for the small percentage of gems that may have a plugin to install.

So it's actually faster to always reinstall plugins for the few gems that have ones, than to make a check for all gems.

Another advantage with this change is that if someone accidentaly bust the plugins folder but don't bust the specifications one, then Bundler will correctly regenerate plugins (where as before it wouldn't).

I tried running this patch on a Gemfile containing 400 gems and this patch shoves around a second.

Solution

Always install plugins, no matter if one of the same version already exist.

I felt like it wasn't need to add a test for this change, but let me know if you'd prefer having one.

Make sure the following tasks are checked

- ### Problem

  When Bundler installs gems, it checks whether a gem plugin needs
  to be installed.
  This check (`Dir.glob`) is expensive and is hotspot when profiling
  Bundler.

  ### Details

  Bundler makes a check to see if a gemspec stub exists for the gem
  being installed. If a gemspec stub already exists and its version is
  the same as the gem being installed, then Bundler assumes that the
  gem plugin was already generated in the past and there is no need to
  generate it again.
  This check was added for performance purpose but it's counter
  productive and has the opposite effect.

  The vast majority of gems don't have a plugin and we are incurring
  the cost of doing a `Dir.glob` for *every* gems to account for the
  small percentage of gems that may have a plugin to install.

  So it's actually much faster to always reinstall plugins for the few
  gems that have ones, than to make a check for all gems.

  Another advantage with this change is that if someone accidentaly
  bust the `plugins` folder but don't bust the `specifications` one,
  then Bundler will correctly regenerate plugins (where as before it
  wouldn't).

  I tried running this patch on a Gemfile containing 400 gems and this
  patch shoves around a second.

  ### Solution

  Always install plugins, no matter if one of the same version already
  exist.
@colby-swandale colby-swandale merged commit fe7fcc7 into ruby:master Feb 20, 2026
92 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants