Repository navigation
Fetch only the selected gemspecs when resolving from legacy indexes - #10141
Open
americodls wants to merge 2 commits into
Open
americodls wants to merge 2 commits into
americodls wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was the end-user or developer problem that led to this PR?
Since RubyGems 4.1.0,
gem installfrom 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-core3.272.0 and its 8 dependencies have 3,003 published versions in total. Gemspec requests to resolvegem install aws-sdk-core --version 3.272.0from a legacy index copy of these gems: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>/versionsreturns 405, so the source gets aGem::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#specfor every listed version, and each call downloads one gemspec:select_local_platformsreads the platform from the full gemspec, although the index already gives it.filter_specsreadsrequired_ruby_versionandrequired_rubygems_version.incompatibilities_forreads 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:
IndexSpecification#installable_platform?uses the platform from the index, asAPISpecificationdoes.filter_specsno longer checks the Ruby and RubyGems requirements of anIndexSpecification.Gem::Resolver#solvechecks 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.incompatibilities_forwidens 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
--forcebehave 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