Skip to content

Replace DataStructures.jl with BinaryHeaps.jl to cut invalidations#3407

Open
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:replace-datastructures-with-binaryheaps
Open

Replace DataStructures.jl with BinaryHeaps.jl to cut invalidations#3407
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:replace-datastructures-with-binaryheaps

Conversation

@ChrisRackauckas-Claude
Copy link
Copy Markdown
Contributor

Summary

Swaps the DataStructures dependency for the new lightweight SciML/BinaryHeaps.jl, which contains the same BinaryHeap / BinaryMinHeap / FasterForward code extracted directly from DataStructures.jl (same upstream source, MIT-licensed, original copyright preserved).

Depends on: SciML/BinaryHeaps.jl#1 being merged and v1.0.0 registered in General.

Motivation

Loading DataStructures.jl causes 6 method invalidation trees from code that is completely unrelated to heap functionality:

Tree 1: kwcall(...sort!...LittleDict...) @ OrderedCollections
Tree 2: get!(h::OrderedDict...)          @ OrderedCollections
Tree 3: merge!(ct::Accumulator...)       @ DataStructures
Tree 4: getkey(dd::LittleDict...)        @ OrderedCollections
Tree 5: Base.IteratorSize(...SortedDict/SortedMultiDict/SortedSet...) @ DataStructures
Tree 6: merge(m::SortedMultiDict...)     @ DataStructures

OrdinaryDiffEq only uses BinaryHeap{T}(FasterForward()), BinaryMinHeap{T}, push!, pop!, first, isempty, empty!, sizehint! — a tiny slice of DataStructures. Pulling in the full package costs 6 invalidation trees and their associated first-call latency for zero benefit.

BinaryHeaps.jl provides the exact same API with zero invalidations.

Changes

  • OrdinaryDiffEqCore: using DataStructures: BinaryHeap, FasterForwardusing BinaryHeaps: BinaryHeap, FasterForward; three DataStructures.FasterForward()FasterForward() in solve.jl.
  • DelayDiffEq: using DataStructures: BinaryMinHeapusing BinaryHeaps: BinaryMinHeap.
  • StochasticDiffEqCore: removed the DataStructures import (it was unused — nothing from the package was referenced).
  • Project.tomls: swap dep/compat entries accordingly; top-level OrdinaryDiffEq/Project.toml drops the unused DataStructures entry.

Diff is 8 files, +10 / -15 lines.

Verification

Locally tested with BinaryHeaps.jl dev-installed:

  • OrdinaryDiffEqTsit5 loads and runs with tstops/saveat (both use BinaryHeap{T}(FasterForward())):
    sol = solve(prob, Tsit5(); tstops=[0.3, 0.6], saveat=[0.25, 0.75])  # ✓ ok
  • DelayDiffEq loads and runs a DDE with a constant lag (uses BinaryMinHeap for propagated discontinuities):
    sol = solve(DDEProblem(...; constant_lags=[1.0]), MethodOfSteps(Tsit5()))  # ✓ ok

Test plan

  • All touched subpackages load without errors
  • Basic ODE solve with tstops/saveat works
  • Basic DDE solve with constant_lags works
  • Full CI passes (awaits BinaryHeaps.jl registration)

🤖 Generated with Claude Code

Swaps the `DataStructures` dependency for the lightweight
[BinaryHeaps.jl](https://github.com/SciML/BinaryHeaps.jl) package, which
contains the same `BinaryHeap` / `BinaryMinHeap` / `FasterForward` code
extracted from DataStructures.jl (same upstream source).

DataStructures.jl causes 6 method invalidation trees (from unrelated
OrderedCollections, Accumulators, and SortedContainers code).
BinaryHeaps.jl causes zero invalidations.

Changes:
- OrdinaryDiffEqCore: `using DataStructures: BinaryHeap, FasterForward`
  → `using BinaryHeaps: BinaryHeap, FasterForward`; drop
  `DataStructures.FasterForward()` qualifier.
- DelayDiffEq: `using DataStructures: BinaryMinHeap`
  → `using BinaryHeaps: BinaryMinHeap`.
- StochasticDiffEqCore: removed unused `DataStructures` import.
- Project.tomls updated accordingly; top-level `OrdinaryDiffEq/Project.toml`
  drops the unused `DataStructures` entry.

Requires BinaryHeaps.jl v1.0.0 to be registered.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants