Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Fetch only the selected gemspecs when resolving from legacy indexes - #10141

Open
americodls wants to merge 2 commits into
ruby:masterfrom
americodls:fix-legacy-index-gemspec-walk
Open

americodls wants to merge 2 commits into
ruby:masterfrom
americodls:fix-legacy-index-gemspec-walk

Conversation

@americodls

Copy link
Copy Markdown

What was the end-user or developer problem that led to this PR?

Since RubyGems 4.1.0, gem install from a source without a compact index, such as GitHub Packages, downloads the gemspec of every published version of each gem it resolves, before it installs anything. The requests run one after another, so the install time grows with the number of published versions.

Example: aws-sdk-core 3.272.0 and its 8 dependencies have 3,003 published versions in total. Gemspec requests to resolve gem install aws-sdk-core --version 3.272.0 from a legacy index copy of these gems:

RubyGems version Gemspec requests
4.0.25 435
4.1.0 3,003
This PR 9

On GitHub Packages, a pinned install of one gem with about 700 published versions takes about 5 minutes on 4.1.0.

GitHub Packages has no compact index: HEAD <source>/versions returns 405, so the source gets a Gem::Resolver::IndexSet. Bundler had the same symptom with GitHub Packages in #5385. rubygems.org has a compact index and is not affected.

Why it happens

The resolver downloads one gemspec for each published version before it selects a version. On a legacy index, each gemspec is a separate request.

#9402 replaced Molinillo with PubGrub. PubGrub needs the full version list of each gem, so the resolver now lists all versions, not only the versions that match the requirement. Three places then call Gem::Resolver::IndexSpecification#spec for every listed version, and each call downloads one gemspec:

  1. select_local_platforms reads the platform from the full gemspec, although the index already gives it.
  2. filter_specs reads required_ruby_version and required_rubygems_version.
  3. incompatibilities_for reads the dependencies of neighbouring versions to widen each dependency range.

Each place alone downloads every gemspec, so all three need a change.

What is your fix for the problem, implemented in this PR?

One change for each place:

  1. IndexSpecification#installable_platform? uses the platform from the index, as APISpecification does.
  2. filter_specs no longer checks the Ruby and RubyGems requirements of an IndexSpecification. Gem::Resolver#solve checks them for the versions the solver selects. If a selected version does not fit, the resolver removes it and solves again. Check gem requirements when locking from legacy indexes #10111 did the same in Bundler.
  3. incompatibilities_for widens a range only over versions whose dependencies are already loaded, or that need no download.

The resolver now downloads the gemspecs of the versions the solver selects, normally one for each installed gem. Sources with a compact index and --force behave as before.

The new tests resolve against Gem::Resolver::IndexSet. They assert which gemspecs are fetched, and that a version with an unmet Ruby or RubyGems requirement is still skipped.

Make sure the following tasks are checked

Gem::Resolver::Specification#installable_platform? reads the platform
from the full gemspec. For an IndexSpecification that is one download
for each version, although the index already gives the platform.
APISpecification answers from its own data. Do the same here.
Since the move to PubGrub, the resolver lists every version of a gem.
From a source without a compact index it then downloads the gemspec
of each version: once to filter by Ruby and RubyGems requirement, and
once to widen dependency ranges over neighbouring versions. A pinned
install of a gem with hundreds of versions makes hundreds of requests
before it installs anything.

Check the Ruby and RubyGems requirements only for the versions the
solver selects, and solve again without a version that does not fit.
Widen a dependency range only over versions whose dependencies are
already loaded. Bundler handles legacy indexes the same way.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant