Remove per-step heap allocations and shared statics from the RT path#15
Closed
joecga4 wants to merge 1 commit into
Closed
Remove per-step heap allocations and shared statics from the RT path#15joecga4 wants to merge 1 commit into
joecga4 wants to merge 1 commit into
Conversation
For real-time hybrid simulation the fixed cost per analyze(1, dt) step matters more than asymptotic solver speed; these are the allocation and copy removals validated in the RTHS profiling work: - EEGeneric/EETruss: no heap allocations per step. Responses are assembled component-wise into preallocated members (const Vector& passthroughs, no operator+/- temporaries), the trial-change check compares component-wise against DBL_EPSILON instead of building a difference vector, and the inertia paths use preallocated scratch. - ShadowExpSite: communication buffers are preallocated in setSize(), removing the first-step latency spike when the buffers used to be grown inside the first send/recv. - ExperimentalSetup: caches whether all trial/out/ctrl/daq factors are 1.0 and skips the scaling passes entirely in that (common) case. - ExperimentalSite::setTrialResponse/setDaqResponse: pointer-equality guards; LocalExpSite passed the site's own vectors, copying them onto themselves every step. - ExperimentalElement: the default getDisp/getVel/getAccel/getTime returned function-local statics shared between ALL elements and sized by whichever called first (latent bug with elements of different numDOF); per-instance members now. - ESTwoActuators2d: the static Vectors of the 4 transformations become preallocated members and the rotation uses addMatrixVector() instead of the heap-allocating operator*. Validated: OneBayFrame local and distributed (3 processes) outputs bit-identical to the pre-change baseline. Co-Authored-By: Claude Fable 5 <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.
For RTHS the fixed cost per
analyze(1, dt)step matters more than asymptotic solver speed. This PR removes the heap allocations, redundant copies and non-reentrant statics found while profiling the per-step path:operator+/-temporaries); trial-change check compares againstDBL_EPSILONcomponent-wise instead of building a difference vector; inertia paths use preallocated scratch.setSize()(removes the first-step latency spike).LocalExpSitepassed the site's own vectors, copying them onto themselves every step.getDisp/getVel/getAccel/getTimereturned function-local statics shared between all elements and sized by whichever called first (latent bug with elements of different numDOF); per-instance members now.addMatrixVector()instead of the heap-allocatingoperator*.Validated: OneBayFrame local and distributed (3 processes) outputs bit-identical to the pre-change baseline.
🤖 Generated with Claude Code