Skip to content

perf: hoist loop-invariant substitution out of JacobianSpectrum - #146

Merged
oameye merged 1 commit into
mainfrom
perf-jacobian-spectrum
Jul 26, 2026
Merged

perf: hoist loop-invariant substitution out of JacobianSpectrum#146
oameye merged 1 commit into
mainfrom
perf-jacobian-spectrum

Conversation

@oameye

@oameye oameye commented Jul 26, 2026

Copy link
Copy Markdown
Member

The harmonic of a uv pair depends only on the pair, not on the eigenvalue, but JacobianSpectrum recomputed it inside the eigenvalue loop. Every (eigenvalue, pair) iteration rebuilt Dict(solution_dict) and ran a symbolic substitute.

Profiling get_jacobian_response showed that loop dominated by Dict{Num} lookups, isequal(::Num, ::Num) and SymbolicUtils hash consing, with substitute the single most expensive primitive at ~530 ns per call.

Substituting once per pair up front, and hoisting _get_uv_pairs and _get_as as well:

Lab frame Jacobian Response allocations
before 2.303 / 2.455 ms 11798
after 1.820 / 1.959 ms 10809

Measured full suite, same machine, alternating runs. For reference the pre-Symbolics-7 stack measured 1.824 ms in the same condition, so this restores parity.

Behaviour is unchanged: the substituted harmonic never depended on the eigenvalue.

Bumps to v0.5.1.

The harmonic of a uv pair depends only on the pair, not on the eigenvalue, but
it was recomputed inside the eigenvalue loop, rebuilding `Dict(solution_dict)`
and running a symbolic `substitute` on every (eigenvalue, pair) iteration.
Profiling the lab frame Jacobian response showed that loop dominated by
`Dict{Num}` lookups, `isequal(::Num, ::Num)` and SymbolicUtils hash consing.

Substituting once per pair up front cuts the benchmark from 2.30/2.46 ms to
1.82/1.96 ms and drops allocations from 11798 to 10809, restoring parity with
the pre-Symbolics-7 stack, which measured 1.824 ms on the same machine.

Bumps HarmonicSteadyState to v0.5.1.
@oameye
oameye merged commit 4e6d658 into main Jul 26, 2026
4 checks passed
@oameye
oameye deleted the perf-jacobian-spectrum branch July 26, 2026 07:37
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.

1 participant