Repository navigation
Skip the preliminary full update for exact-pinned targets - #9952
Draft
jeffwidman wants to merge 1 commit into
Draft
jeffwidman wants to merge 1 commit into
jeffwidman wants to merge 1 commit into
Conversation
Derive exact base requirements from applicable explicit targets instead of resolving the complete graph to rediscover those versions. Keep the constrained resolution and fall back for nonexact targets, explicit sources, overrides, and Bundler self-updates. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4 tasks done
4 tasks done
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.
WIP - please ignore while this is in Draft.
Thanks!
-Jeff
What was the end-user or developer problem that led to this PR?
For a targeted update, Bundler can resolve the dependency graph twice: first
as a full update to discover the versions of the explicitly unlocked gems,
then with those versions pinned while retaining the other update constraints.
The first resolution is useful when Bundler must choose a target version.
However, when every explicit target already has an applicable exact requirement,
its version is known before that resolution starts. Solving the graph to discover
those same versions repeats work without providing new target-version information.
The final constrained resolution is still needed to check whether the complete
dependency graph can satisfy the request.
This occurs with ordinary
bundle update GEMandbundle lock --update GEMrequests after changing exact requirements, as well as automated updates.
For example, Dependabot's public lockfile updater pins the chosen versions
before resolving.
Repeating a full resolution in each eligible invocation adds up on larger graphs.
What is your fix for the problem, implemented in this PR?
Derive the exact base requirements directly when all explicit update targets
have exactly one applicable, exact, source-less requirement, and skip only the
preliminary full-update resolution.
The change adds 21 lines in
Definition, with no cache, serialization, newconfiguration, or concurrency. It retains the existing path for nonexact or
mixed requests, indirect-only targets, explicit source targets, active overrides,
and explicitly unlocked Bundler self-updates.
Two details are important for correctness:
Resolver::Base#requirements, which has already filtered out declarationsfor excluded platforms. An inactive exact declaration must not restrict a gem
that is needed transitively on the active platform.
Otherwise an existing downgrade-prevention floor can reject a valid exact
downgrade. This also matters when a caller changes requirements after building
the definition.
The final constrained resolver and its existing conflict-relaxation behavior
remain in place. This preserves necessary indirect downgrades without
unnecessarily updating unrelated direct dependencies.
Benchmarks
Isolated native patch on current master
An offline synthetic fixture has 20 direct dependencies, 120 locked gem names,
and 12 available versions per name. All gems start locked at 1.0.0; the first
direct dependency is changed to
= 1.11.0and explicitly unlocked. Each gemdepends on the gems 20 and 21 positions later, where present, with
>= 1.0.0requirements.
The actual baseline and patched libraries were compared in seven alternating
pairs, after one discarded warmup per library. Every sample used a fresh Ruby
process and the same unchanged input lockfile. Timing covers
Definition.build,resolve_with_cache!, andto_lock, including archive metadata reads, butexcludes fixture generation and Ruby startup. These runs were performed after
the test suite finished.
This is 6.5% less median CPU and elapsed time on this synthetic workload.
All 14 measured runs produced the same lockfile SHA-256. It is a small repeated
local benchmark, not a confidence interval or a prediction for other graphs.
Standalone synthetic reproduction
Save the following as
exact-pin-benchmark.rb. With unmodified and patchedcheckouts at the same base revision, run:
The command passed locally with the results above. It generates only synthetic
gems in a temporary directory, uses cached resolution without a registry, and
fails if either library fails or the lockfile hashes differ.
Existing standalone Dependabot measurements
These measurements tested only this exact-pin optimization, using a runtime
prototype of the same eligibility checks and exact-base-requirement replacement.
They are not measurements of the other performance changes being investigated.
The local jobs used Ruby 4.0.5, Bundler 4.0.22, and RubyGems 4.0.14. CPU is the sum
of native helper process CPU measured with
Process::CLOCK_PROCESS_CPUTIME_ID,not total updater/container CPU. All proposed dependency records and all proposed
text/binary file contents matched between each baseline and optimized pair.
Eligible lockfile-writer invocations went from two solver passes to one.
The update checkers were not optimized. There was no observed HTTP-request
reduction from this shortcut; the demonstrated saving is repeated native CPU work.
These were individual paired local jobs on a shared development host, with live
network access. The two complete-job comparisons overlapped with other runs, so
they are not controlled wall-time trials or statistical estimates. The large
repository sample was not a complete update job. These numbers demonstrate the
opportunity, not a universal percentage or a benchmark of this patch on current
master.
Validation
Current branch base:
a099e068a86c0a912d558b2c107c6c263cb5b4ff.Local validation uses Linux MRI Ruby 4.0.5 and the checked-out Bundler/RubyGems
4.1.0.beta2.
ruby bin/rspec spec/bundler/definition_spec.rb spec/commands/update_spec.rb --format progress --seed 45123conservative fallbacks, indirect downgrades, unrelated direct dependencies,
and excluded-platform requirements.
ruby bin/rubocop lib/bundler/definition.rb spec/bundler/definition_spec.rb spec/commands/update_spec.rbpatched libraries at the same base revision, without replacing the
implementation with a runtime prototype:
error classes/messages.
policies, exact downgrades, missing versions, conflicts, prereleases,
platforms, runtime requirements, source-scoped targets, overrides, and
requirements changed after definition construction.
ruby bin/parallel_rspec -n 4 spec --seed 45123The network-dependent realworld suite, RubyGems test-unit suite, and the
Windows/JRuby/TruffleRuby matrix have not been run locally.
Make sure the following tasks are checked