Look up gems for gem fetch through the compact index - #9796
Open
segiddins wants to merge 1 commit into
Open
Conversation
`gem fetch` looks gems up through Gem::SpecFetcher, which asks a source for its entire index -- the compact index `versions` file when the source serves one, 23MB of it for rubygems.org on a cold cache, and the Marshal index otherwise -- and then fetches a Marshal gemspec for every version that matches. `gem install` resolves through Gem::Resolver::BestSet, which reads only the `info` file of the gem it is looking for. Look gems up through a BestSet instead, so `gem fetch a` reads `/info/a` rather than the whole index, and fetches only the gemspec of the version it downloads. Platform preference and the reporting of specs rejected for another platform are unchanged. Gem::Source uses Gem::RemoteFetcher without requiring it, relying on its callers to have loaded it, and it cannot require it eagerly: Bundler loads rubygems/source on boot, where pulling in net/http breaks bundles that do not include its dependencies. Require it from the command instead, the way the sources command already does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
segiddins
force-pushed
the
segiddins/gem-fetch-through-the-compact-index
branch
from
August 22, 2026 03:56
df4a1dc to
3996b60
Compare
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.
gem fetchlooks gems up through Gem::SpecFetcher, which asks a source for its entire index -- the compact indexversionsfile when the source serves one, 23MB of it for rubygems.org on a cold cache, and the Marshal index otherwise -- and then fetches a Marshal gemspec for every version that matches.gem installresolves through Gem::Resolver::BestSet, which reads only theinfofile of the gem it is looking for.Look gems up through a BestSet instead, so
gem fetch areads/info/arather than the whole index, and fetches only the gemspec of the version it downloads. Platform preference and the reporting of specs rejected for another platform are unchanged.Gem::Source now requires rubygems/remote_fetcher, which it has always used without loading: until now every caller of #dependency_resolver_set had loaded Gem::SpecFetcher, which requires it, first.
What was the end-user or developer problem that led to this PR?
I have a private gem server that only serves the compact index, no marshal, and
gem installwas succeeding butgem fetchfailed.What is your fix for the problem, implemented in this PR?
Allow
gem fetchto prefer the compact index over the full index, mirroringgem installbehavior.Make sure the following tasks are checked