-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduced heap allocation for Quintic Bezier Function #3481
Reduced heap allocation for Quintic Bezier Function #3481
Conversation
This is to reduce runtime heap allocation. Any SimTK::Matrix in SegmentedQuinticBezierToolkit is replaced by std::vector<SimTK::Vec6>.
The `m` referred to it being previously stored in a matrix.
Updates the unitests to use Vec6 for control points.
In SmoothSegmentedFunctionData constructor initializer list did not match the member definition order.
Hi, @adamkewley @nickbianco @carmichaelong , the unit test still failing on unrelated issue, but perhaps any of you would already like to take a look at this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't see anything that fundamentally changes the behavior/algorithm (and the fact that high-level tests etc. still pass for such a fundamental class change indicates that it probably behaves the same).
I'd suggest, if there is time (this is much less important) a separate PR in which X
, Y
, these Vec6
's etc. are tied into more expressive types than they currently are. A lot of the code is messy (pre- and post-PR) because a lot of it is juggling those types around rather than designing specific types for each part of the problem.
E.g. std::pair<SimTK::Vec6, SimTK::Vec6>
is an improvement over the original return value, but it might be better (depending on what "Vec6" means here) to use explicit types:
struct QuinticBezierControlPoint final {
// 6 double values with appropriate names, if they aren't a truly 6-d quantity
};
struct QuinticBezierSurfacePoint final {
QuinticBezierControlPoint x;
QuinticBezierControlPoint y;
};
std::vector<QuinticBezierSurfacePoint> controlPoints;
// etc.
replaces SegmentedQuinticBezierToolkit::calcQuinticBezierCornerControlPoints return value by ControlPointsXY instead of a std::pair. This is to clarify the content, which is lost after a few layers. See opensim-org#3481 (comment)
Added runtime check that size is larger than 0, as it breaks for nbezier=0, see opensim-org#3481 (comment)
…uced-heap-allocation
Thanks @adamkewley I think I got most of your comments in a straightforward way. Perhaps check: I agree with your point that the XY points are probably a Vec2 (or something like that), but indeed better to set up a new pr (I can look into this). Thanks! |
The failures on Windows are related to some issue with the CI finding the SWIG install. Working on a fix for that now. The Mac failure was due to a CMC test that is notorious for failing sporadically (we should fix that at some point). I re-ran the tests, but if that is the only failing, don't let it hold you up from merging once you're happy with the review changes. |
I checked your resolutions and they're fine |
Also changed `NUM_SAMPLE_PTS` to be a constexpr, with assertion.
This to be compliant with c++_11
…uced-heap-allocation
This results in more consistent use of `int` for indexing and size.
Well, finally landed on using Care to give it another look @adamkewley ? |
Seems fine 👍 |
🎈 |
This PR changes the type of the quintic bezier control points to a
Vec6
(instead of a dynamicVector
).As the name suggests, the quintic bezier toolkit works with six-control points.
These control points are currently stored in either a
SimTK::Vector
or in the columns of aSimTK::Matrix
.Changing these to use a
SimTK::Vec6
or astd::vector<SimTK::Vec6>
respectively reduces runtime heap-allocation, resulting in 8% speed increase (wall clock time) when simulating Rajagopal model.Brief summary of changes
SegmentedQuinticBezierToolkit
:SimTK::Vector
toSimTK::Vec6
,SimTK::Matrix
tostd::vector<SimTK::Vec6>
,calcQuinticBezierCornerControlPoints
to astd::pair
instead ofSimTK::Matrix
with two columns.mX
andmY
variable names toctrlPtsX
andctrlPtsY
respectively.SmoothSegmentedFunction
,SmoothSegmentedFunctionFactory
andtestSmoothSegmentedFunctionFactory
to fix interfacing to the above.Testing I've completed
testSmoothSegmentedFunctionFactory
.CHANGELOG.md
This change is