perf(scroll): scalar cross-product + lazy nozzle outputs (bit-identical, ~8%) - #110
Merged
Conversation
Two hot-path micro-optimizations on the scroll force/flow path, verified to leave examples/scroll_compressor.py results unchanged to all printed digits (mdot 55.175673362688805 g/s, vol-eff 91.95998551975654%, eta 74.61003492585036%): - symm_scroll_geo.SA_forces: replace two `np.cross([x,y,0],[a,b,0])[2]` calls with the scalar z-component (x*b - y*a). np.cross pulls in normalize_axis_tuple + broadcasting machinery for what is one multiply-subtract. - flow_models.IsentropicNozzle: only `mdot` is returned in the default case, so the throat-state / speed-of-sound / Mach-number work is now computed lazily behind the OUTPUT_VELOCITY/OUTPUT_MA guard instead of on every call. ~8% faster on the full scroll_compressor.py example (np.cross ~7%, nozzle ~1%), no behaviour change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
Two small, bit-identical hot-path optimizations found while profiling
examples/scroll_compressor.py. No behaviour change —scroll_compressor.pymdot / volumetric efficiency / adiabatic efficiency are unchanged to every printed digit (mdot 55.175673362688805 g/s, vol-eff 91.95998551975654%, η 74.61003492585036%), verified before/after.Changes
symm_scroll_geo.SA_forces— replace twonp.cross([x,y,0],[a,b,0])[2]calls with the scalar z-componentx*b - y*a. Only the z-component is ever used, andnp.crosspulls innormalize_axis_tuple+ broadcasting machinery for what is a single multiply-subtract.flow_models.IsentropicNozzle— the default call returns onlymdot, but the throat temperature/density, speed of sound, velocity and Mach number were computed on every call. They're now computed lazily, behind theOUTPUT_VELOCITY/OUTPUT_MAguard.mdotis bit-unchanged.Impact
~8% faster on the full
scroll_compressor.pysolve (np.cross ~7%, nozzle ~1%), measured best-of-N. Both are pure overhead removal — exact same numerics.Context
These came out of a profiling exercise (native sampling) showing the scroll solve is dominated by PDSim's own Python/Cython framework + numpy (the EOS is only ~13–20% on modern CoolProp), so small-array-numpy and wasted-compute removals like these are free wins. Larger gains (Cythonizing the per-step callbacks, caching the per-θ geometry kernels) are noted as follow-ups.
🤖 Generated with Claude Code