Repository navigation
Unroll CompositeControllerCache dispatch (non-stiff Default step! allocation-free) - #4647
Merged
ChrisRackauckas merged 5 commits intoSep 27, 2026
Conversation
Runtime indexing of the heterogeneous controller-cache tuple forced dynamic dispatch on every Default/Composite step. Match the existing @generated pattern used for dense interpolants and DefaultCache. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.09.26-dd393fe Agent-Model: unknown (Cursor auto) Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-default-alloc/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-default-alloc/log.txt)
Replace twelve copies of the unrolled cache-index body with one @eval loop over (fname, extra_args), and match generic_dense.jl's throw("Cache $current…") error style. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.09.26-dd393fe Agent-Model: unknown (Cursor auto) Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-default-alloc/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-default-alloc/log.txt)
Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.09.26-dd393fe Agent-Model: unknown (Cursor auto) Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-default-alloc/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-default-alloc/log.txt)
Nesting $(extra_args...) inside the @generated quote left the name unbound at generate time. Splice QuoteNode(fname/extra_args) at @eval and build the call Expr in the generator instead. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.09.26-dd393fe Agent-Model: unknown (Cursor auto) Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-default-alloc/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-default-alloc/log.txt)
any(f.(tuple)) materializes a Bool NTuple each Default/composite step on Julia LTS (3184 B); any(f, itr) matches alg_order and is 0 B. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.09.26-dd393fe Agent-Model: unknown (Cursor auto) Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-default-alloc/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-default-alloc/log.txt)
ChrisRackauckas
marked this pull request as ready for review
September 27, 2026 14:43
ChrisRackauckas
referenced
this pull request
Sep 29, 2026
* Bump DiffEqBase to 7.21.3 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqBDF to 2.4.12 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqSDIRK to 2.9.7 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqRosenbrock to 2.7.5 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqLowOrderRK to 2.2.6 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqTsit5 to 2.1.5 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqVerner to 2.4.2 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqSymplecticRK to 2.2.3 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
What changed and why
CompositeControllerCachemethods indexed the heterogeneouscachestuple (andalg.algs) with a runtimecurrentindex. That is type-unstable, so every Default / Composite step paid dynamic-dispatch allocations inaccept_step_controller,stepsize_controller!, andstep_accept_controller!. This PR replaces those wrappers with@generatedunrolledif current == idispatch (factored through one@evalloop over(fname, extra_args)), matching the existing pattern ingeneric_dense.jl/DefaultCacheperform_step!.Separately, on Julia LTS (1.10),
alg_extrapolates(::CompositeAlgorithm)usedany(alg_extrapolates.(alg.algs)), which materializes a Bool NTuple every step (~3184 B). This is nowany(alg_extrapolates, alg.algs)(same form asalg_order), so LTS non-stiff Defaultstep!is also 0 B.A regression test asserts non-stiff
DefaultODEAlgorithmstep!allocates 0 bytes after warm-up. Stiff Default steps still allocate ~3.9–4.9 KB viaunwrap_alg(alg_utils.jl:958); that remaining allocation is out of scope for this PR.Diagnosis (what the profile showed)
Julia 1.12 —
Profile.Allocsonstep!(DefaultODEAlgorithm())after warm-up (sample_rate=1.0, 20 steps):step!bytes: Tsit5=0, Default=1536. After controller unroll: Default=0 (non-stiff).Julia LTS 1.10.12 — after the controller fix, CI still failed with
3184 == 0. Profile.Allocs attributed the remaining bytes to broadcast inalg_extrapolates:LTS step! bytes: master=4592, PR (controllers only)=3200, PR (+ alg_extrapolates fix)=0.
Verification
typoson changed files (exit 0)GROUP=Coreon Julia 1.12: 57/57 passed (includes allocation test)Failing-before / passing-after
Julia 1.12 — before (master controllers.jl):
Julia 1.12 — after (this PR):
Julia LTS — before (broadcast
alg_extrapolates, matches CI):Julia LTS — after (
any(f, itr)):Before/after numbers
Pinned and interleaved review measurements (
JULIA_NUM_THREADS=1, pinned core):step!after warm-up (non-stiff Default Lorenz): 1.12: 1536 → 0 B; LTS: 4592 → 0 B.Behaviour-equivalence check
Fingerprints identical before/after for Default on Lorenz and Van der Pol (μ=1e6) on each Julia version:
1.12: Lorenz naccept=1298, nreject=34, nf=7997, alg_choice=[1,3], switch_idxs=[1,524,527]; VdP naccept=1488, nreject=564, nf=10479, same switches — 12/12 match
LTS: master and PR fingerprints bitwise-identical (Lorenz naccept=1308 / alg_choice=[1] differs from 1.12 FP path, not from this PR)
Independent review: Claude Code (Opus 5.5), final pass at 8347567: MERGE, low risk, high confidence. 22 ODE composite cases plus a DDE are bitwise identical to master;
code_typedshows the unrolled dispatch is statically resolved; Default VdP is faster in every pinned round. On Julia 1.10.12 the test fails on master (4576 == 0) and passes at head, and Default Lorenzstep!drops from 8689 B/step (master) to 0. The LTS-onlyalg_extrapolatesbroadcast fix is verified semantically identical.What was not verified
OrdinaryDiffEqumbrella test suiteunwrap_algallocations (explicitly out of scope)Please ignore until reviewed by @ChrisRackauckas.
Risk assessment
CompositeControllerCacheusers;alg_extrapolatesform is semantically identical; behaviour verified bitwise-identicalCompositeAlgorithmand default-solver useralg_extrapolatesbroadcast); before/afterstep!1536→0 (1.12) and 4592→0 (LTS); behaviour fingerprints match; Core+Default green on both versions; independent review confirmedalg_extrapolatesbroadcast (fixed in 8347567).🤖 Generated with Cursor Agent (model: auto), orchestrated by Claude Code (claude-opus-5-5[1m]) session https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv
Made with Cursor
Risk assessment
T.typesaccesses Julia’s internal type representation. Undisclosed behavioral details:any(f, tuple)short-circuits trait evaluation, and invalid cache indices now explicitly throw strings; neither establishes a supported-public-API break requiring a major release.83475670ae4701b2c712d39e4b0b4c14d8d3c8d3: 256 successful, seven failed, three skipped checks. All seven failures are pre-existing; no test regression identified.SciMLSensitivity.jl/Core1/1 / Downstream Tests - Core1has the same MooncakeAnyconstructor error on head and master.downgrade-sublibraries / test (lib/DiffEqBase)anddowngrade-sublibraries / test (lib/OrdinaryDiffEqDifferentiation)have matching callback anddiag(::ScalarOperator)errors on head and master. Sublibrary Julia 1 Core checks forGlobalDiffEq,OrdinaryDiffEqDifferentiation, andOrdinaryDiffEqNonlinearSolvehave matching unsupported-callback, ScalarOperator, and Trapezoid mass-matrix errors on head and master.tests / GPU (julia 1, self-hosted Linux X64 gpu) / Tests - GPU (Julia 1)has the same QNDFgpu_mismatchon head and master. Core and Default checks pass across LTS, release, and prerelease, including QA. No GitHub reviews or review comments exist.🤖 Risk assessment posted by an AI agent (fleet master) — harness: Codex CLI 0.156.1 (Mac) / gpt-6-astra; dispatched by Claude Code head, model claude-opus-5-5[1m]
Conversation: local Claude Code session 3cd6500a-1f81-46b5-ac0b-c466e15b6a53 on Chris's Mac (session ID, no URL)