add compile-time optimization based on parameter values #124
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.
Status: Waiting for JSCompiler release
In multibody models, many parameters are sparse, e.g., arrays like
[1, 0, 0]
or diagonal inertia matrices. Allowing JSCompiler to make use of this information when simplifying the system and generating code can lead to a 2x performance boost for multibody simulations. The downside is of course that those parameters cannot be changed without recompiling. It's thus only worthwhile for simulations where runtime is longer than compile time.To see why this makes such a big difference, consider the expression
R'*I*R
where the matrices are both 3x3. Without any structure, this expands to the computationIf we know that
R
is diagonal (very common case), we getIf we know that
I
is diagonal we getand if both are diagonal, we get
The PR #123 adds an explicit option to handle structural zeros in inertia matrices only, but this PR adds more of a nuclear option using
JuliaSimCompiler.freeze_parameters
, replacing all parameters that have the value 0 or 1 with their value. For a simple model of a car, this improved both simulation and RHS time by 2x.Code for the above