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

Build Gem::Requirement.default without parsing ">= 0" - #10002

Merged
hsbt merged 1 commit into
ruby:masterfrom
linyiru:rubygems-requirement-default
Nov 4, 2026
Merged

hsbt merged 1 commit into
ruby:masterfrom
linyiru:rubygems-requirement-default

Conversation

@linyiru

@linyiru linyiru commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Part of #9998, a set of small, independent boot-time improvements.

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

Gem::Requirement.default parsed the string ">= 0" with the requirement pattern on every call, only for parse to map it back to DefaultRequirement. Gem::Dependency.new calls it for every dependency without a version; bundler/setup called it 1,144 times in the app below.

Measured on master (c2380f6) in a Rails app with 450 activated gems and a 1,500-line lockfile, Ruby 3.4.12, macOS arm64.

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

Gem::Requirement.new with no arguments already sets @requirements = [DefaultRequirement], the same state, so default builds it that way. Each call still returns a new object, since a requirement can be concated. The added test pins equality, the internal pair and the fresh object. 1,000 calls: 1.05 → 0.28 ms, about 0.9 ms per bundler/setup here.

What this costs

None that I can see: one line.

Make sure the following tasks are checked

Requirement.default parsed the string ">= 0" with the requirement
pattern on every call, only to map it back to DefaultRequirement. A
requirement built with no arguments already holds DefaultRequirement,
so build it that way. Gem::Dependency.new calls this for every
dependency without a version, which Bundler does over a thousand times
while loading a large lockfile.
@hsbt
hsbt merged commit c812555 into ruby:master Nov 4, 2026
114 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.

2 participants