Skip to content

Parse each version requirement once per process - #77

Open
czj wants to merge 1 commit into
mainfrom
perf/version-checks
Open

czj wants to merge 1 commit into
mainfrom
perf/version-checks

Conversation

@czj

@czj czj commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Needs a review before merging: opened without a final independent review. Three review rounds found concurrency bugs in this area; the fixes for the last round were not reviewed. Auto-merge is off on purpose.

Every version check (chrome?(">= 100"), mac?, platform.name on a Mac) built a Gem::Requirement from its string and a version from the browser's: 18 objects per call. Both are now kept in Cache, bounded like the rest and built outside its lock.

  • Fewer objects: chrome?(">= 100") 18 to 5 objects; platform.name on a Mac 12 to 0; a Mac Safari request asking four versions 8.7 to 3.6 µs.
  • Attacker input stays out: a version longer than 32 bytes, or not a String, is built each time and never reaches RubyGems' own caches.
  • Cache off unchanged: with cache_size = 0 each object keeps the last version it used, as before.
  • Conflicts with the odd-requirements fix on the same lines: rebase after it.
Proof

script/corpus_snapshot.rb byte-identical to main's; cache on and off give the same answers; rake test and rubocop pass.

chrome?(">= 100"), mac?, platform.name on a Mac and every other version check built a Gem::Requirement from its string and, on each new browser, a version from the user agent's. Both are now kept in Cache, bounded like the rest and built outside its lock; a version longer than 32 bytes, or not a String, is still built each time and never reaches RubyGems' own caches, and each object still keeps the last version it used when the cache is off.

Assisted-by: Claude Opus 5.5 [Claude Code]

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