Skip to content

[DRAFT] Resolve selective copies lazily and cheaply - #4682

Draft
pablomh wants to merge 4 commits into
pulp:mainfrom
pablomh:solver-perf
Draft

pablomh wants to merge 4 commits into
pulp:mainfrom
pablomh:solver-perf

Conversation

@pablomh

@pablomh pablomh commented Dec 1, 2026

Copy link
Copy Markdown

Problem

Dependency solving loads every source and destination repository version into
libsolv before it can resolve anything, so a copy that selects a handful of units
pays for the full versions. The load path also bound one query parameter per
content unit, fetched fields nothing reads, rebuilt the provides index per module,
wrote per-package debug dumps by default, and reloaded a repeated version for
every config entry. Provider lookups were issued one capability at a time, and
copy entries that shared a source overwrote each other when solving was enabled.

Change

Four commits, each self-contained:

  1. Reduce the dependency-solving load cost — load packages, modules and
    defaults through the database-side unnest subquery; drop unused fields and
    no-op conversions; build the provides index once per load phase; load each
    version once; skip child resolution for copy-all; default the debug dumps off.
  2. Resolve selective copies lazily — split the solver into a resolver and a
    libsolv policy; expose each version through a source with three modes (full
    version, selection, installed capability index); fetch only providers the
    destination cannot satisfy; follow rich-dependency operands and
    arch-qualified capabilities; link modular packages to their modules; fall back
    to the full load whenever the partial pool cannot resolve faithfully.
  3. Keep lazy exploration cheap and consistent — look providers up against the
    domain with the version id set as a filter; index the capability names of
    provides so a batch of names and provides is one query; cache built units;
    defer path capabilities to one file scan per round; price provider queries and
    module rows in a work budget so an attempt that cannot beat the full load
    abandons early; one lookup path for every version size. Add a coverage map
    over resolver transitions and input shapes, with meta-tests that fail when a
    transition loses its test or exclusion.
  4. Merge copy entries that repeat a source — entries sharing source,
    destination and base version become one entry with the union of their
    selections; a source paired with more than one destination is rejected with a
    validation error before a task is dispatched.

Migration

0075_package_provides_gin adds a concurrent expression GIN index over the
capability names of provides (jsonb_path_query_array + jsonb_ops). It
depends only on the previous rpm migration, so it applies on the oldest
supported pulpcore (3.118).

Results

Case Time Worker peak RSS
Copy-all, small / medium / large 66% / 77% / 90% less ≈flat (+5%)
Three-package selection vs full load (40,986 units) 93% less not separately probed
Alma 9 systemd / wide / module+dnf (9.4k units) 90% / 72% / 70% less 418 → 194 MB (−54%)
22k-unit version 50% less 750 → 285 MB (−62%)
Katello incremental copy slice / task 55% / 22% less 54%–62% lower
40,986-unit version load 3.5% / 6.5% faster not separately probed

The RSS figures compare the worker peak for the same selective copy. For the
22k-unit probe the full solve peaks at 750 MB and the lazy resolver at 285 MB;
the membership set itself is 6.8 MB, against the 750 MB of rows a full load
converts.

Every lazy result matched the full solve in the Katello end-to-end run, and the
differential check (SOLVER_DIFFERENTIAL_CHECK) remains available as an opt-in
verification. Budgets fall back to the full load rather than returning a partial
resolution.

Tests

  • unit suite: 242 passed, 1 skipped
  • 34-stream module sweep
  • Katello incremental-CV E2E: identical membership on the copy
  • coverage meta-tests over transitions and input shapes

Notes

  • The only API change is duplicate-source normalization: merge when the
    source/destination/base match, reject when one source targets two
    destinations. dependency_solving=False is unchanged.
  • #4680 touches the same file; this branch will be rebased onto main after it
    lands (one import-block conflict).

🤖 Generated with Claude Code

Loading a repository version for the solver bound one query parameter
per content unit, scanned the version's content twice for packages,
fetched fields nothing reads, wrote per-package decision dumps for every
copy because SOLVER_DEBUG_LOGS defaulted to true, rebuilt the pool
provides index once per module and default, and loaded a repeated
version again for every config entry. Copy-all also resolved child
content even though every child is already selected, which dominated a
46k-unit copy on the Katello box.

Load packages, modules and defaults through the database-side unnest
subquery, stop fetching unused fields and running no-op conversions,
build the provides index once per load phase, load each version once,
skip child resolution for copy-all, default the debug dumps off, and use
RepositoryVersion.get_content() for version scoping.

Measured on a 40,986-unit version: load is 3.5% faster with filelists
and 6.5% faster without.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions github-actions Bot added multi-commit Added when a PR consists of more than one commit no-issue labels Dec 1, 2026
pablomh and others added 3 commits December 2, 2026 08:11
Dependency solving loaded every source and destination version into the
solver even when the copy selected a handful of units, so the cost was
paid whether or not the destination could satisfy the selection.

Split the solver into a dependency resolver and a libsolv policy, and
expose each repository version through a content source with three
modes: the whole version, the selection, or an installed capability
index. Load only the selected units, fetch providers of the capabilities
the destination cannot satisfy on demand, follow rich-dependency
operands and arch-qualified capabilities, link modular packages to their
modules, and fall back to the full load for anything the partial pool
cannot resolve faithfully.

The index migration depends on the previous rpm migration alone, not on
a core migration newer than the oldest supported pulpcore, so it applies
on 3.118 deployments.

Measured on a 40,986-unit version with a three-package selection and a
full destination: the lazy attempt takes 7% of the full load's time
(1.3 s vs 18.0 s) and builds 8 solvables instead of 70,711, resolving
identical units.

Co-Authored-By: Claude Code <noreply@anthropic.com>
A lazy attempt issued one provider lookup per capability per source.
Scoping each lookup through the version's content-id array hashed that
array per statement (42 ms per 50 capabilities at 9.5k units, 122 ms at
22k), and a second version-scoped strategy above a size threshold had to
be kept in step for no benefit.

Look providers up against the domain, filtered to the version by its id
set, with the local domain column keeping the planner on the package
table. Index the capability names of provides so a whole batch of names
and provides is answered by one query, cache the units a lookup builds,
defer path capabilities to one file scan per round, and price provider
queries and module rows by measured cost in the work budget so an
attempt that cannot beat the full load abandons early. One lookup path
serves every version size: the membership set costs an order of
magnitude less than the rows a full load would convert (6.8 MB vs 750 MB
at 22k units). Resolve ids before materializing rows in name groups and
installed lookups, which were reading every same-name package in the
domain.

Add a coverage map over the resolver transitions and input shapes, with
meta-tests that fail when one loses its test or exclusion, and the
transition tests that were missing. Drop the dead helpers the single
path left behind.

Measured on Alma 9 (two sources): systemd 90% faster (0.18 s vs 1.9 s),
389-ds-base + dnf 72% faster (1.5 s vs 5.3 s), a module + dnf selection
70% faster (1.6 s vs 5.3 s), with identical membership; worker peak RSS
for a lazy selective copy is 54% lower (194 MB vs 418 MB) at 9.4k units.

Co-Authored-By: Claude Code <noreply@anthropic.com>
When dependency solving is enabled, the resolver keys its candidates by
source repository version: two entries sharing a source but targeting
different destinations silently lost one destination, and two entries
sharing the source and destination but selecting different content kept
only the last selection.

Normalize the config before resolving: entries sharing a source,
destination and base version become one entry holding the union of their
selections (an entry without a selection still copies everything), and a
source paired with more than one destination is rejected. The viewset
runs the same normalization so the request fails with a validation error
before a task is dispatched.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@pablomh
pablomh marked this pull request as draft December 2, 2026 12:46
@pablomh pablomh changed the title Resolve selective copies lazily and cheaply [DRAFT] Resolve selective copies lazily and cheaply Dec 2, 2026

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

multi-commit Added when a PR consists of more than one commit no-issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant