Skip to content

Solver: add been_intersected_with / been_reduced_by dedup caches #64

@doubleailes

Description

@doubleailes

Background

Audit against rez/src/rez/SOLVER.md flagged that rer's PackageVariantSlice is missing two per-slice caches that rez uses to skip redundant work:

  • been_intersected_with — records ranges a slice has already been intersected with; `intersect()` short-circuits if the incoming range is already covered.
  • been_reduced_by — records package requests a slice has already been reduced by; `reduce_by()` short-circuits on repeats.

In rez these are part of the "optimised mode" path on `_PackageVariantSlice` (`rez/src/rez/solver.py:566+`).

Impact

  • Correctness: none. rer redoes work that rez would skip, but the result is identical. This is consistent with rer matching rez 1:1 on the 188-case benchmark.
  • Performance: rer is already faster than rez on the benchmark (~44s vs ~206s), so there's no urgency, but the headroom is real — the redundant intersect/reduce work shows up in the hot loop.

What to do

  1. Add two fields to `PackageVariantSlice` (`crates/rer-resolver/src/rez_solver/variant.rs:476-493`):
    • `been_intersected_with: FxHashSet` (or equivalent)
    • `been_reduced_by: FxHashSet` (or equivalent)
  2. In `intersect()` (`variant.rs:588-606`): if the incoming range is in `been_intersected_with`, return `Unchanged`.
  3. In `reduce_by()` (`variant.rs:609-674`): if the incoming request is in `been_reduced_by`, return `Unchanged`.
  4. Decide on cache cloning behaviour: rez keeps the cache when entries are unchanged, drops it on `copy_with_entries`. Match that.
  5. Re-run the rez benchmark and report timing delta.

References

  • rer slice: `crates/rer-resolver/src/rez_solver/variant.rs:476-493`
  • rez slice: `rez/src/rez/solver.py:566+`
  • SOLVER.md mentions these as part of the "immutability optimization" pattern (~line 158)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions