perf: hoist loop-invariant substitution out of JacobianSpectrum - #146
Merged
Conversation
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.
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.
The harmonic of a uv pair depends only on the pair, not on the eigenvalue, but
JacobianSpectrumrecomputed it inside the eigenvalue loop. Every(eigenvalue, pair)iteration rebuiltDict(solution_dict)and ran a symbolicsubstitute.Profiling
get_jacobian_responseshowed that loop dominated byDict{Num}lookups,isequal(::Num, ::Num)and SymbolicUtils hash consing, withsubstitutethe single most expensive primitive at ~530 ns per call.Substituting once per pair up front, and hoisting
_get_uv_pairsand_get_asas well: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.