-
Notifications
You must be signed in to change notification settings - Fork 357
perf(kinbody): skip redundant GetDOFValues recompute in SetDOFValues #1564
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
Open
Puttichai
wants to merge
12
commits into
production
Choose a base branch
from
optimize_setdofvalues_bookkeeping_2_20260609
base: production
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+55
−11
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
975ecd6
perf(kinbody): skip redundant GetDOFValues recompute in SetDOFValues
Puttichai de84311
Merge remote-tracking branch 'origin/production' into optimize_setdof…
Puttichai b08d9fc
Merge remote-tracking branch 'origin/production' into optimize_setdof…
Puttichai fb0cbbe
Merge remote-tracking branch 'origin/production' into optimize_setdof…
Puttichai 5ef43a8
chore: update comments
Puttichai caa1cc9
chore: reuse existing expecteddof
Puttichai 5b018d9
perf: avoid unnecessary setting of _vTempJoints in no-NaN path
Puttichai 09b1e1b
Merge remote-tracking branch 'origin/production' into optimize_setdof…
Puttichai b3a7db8
Merge remote-tracking branch 'origin/production' into optimize_setdof…
Puttichai 3838d55
chore: add clarification comment
Puttichai 49e3d45
perf: skip GetDOFValues when the given dofindices covers all dofs
Puttichai 4498d7d
Merge remote-tracking branch 'origin/production' into optimize_setdof…
Puttichai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2271,27 +2271,71 @@ void KinBody::SetDOFValues(const dReal* pJointValues, int dof, uint32_t checklim | |
| if( dof == 0 || _veclinks.size() == 0) { | ||
| return; | ||
| } | ||
| int expecteddof = dofindices.size() > 0 ? (int)dofindices.size() : GetDOF(); | ||
| OPENRAVE_ASSERT_OP_FORMAT((int)dof,>=,expecteddof, "env=%s, body '%s' not enough values %d<%d", GetEnv()->GetNameId()%GetName()%dof%GetDOF(),ORE_InvalidArguments); | ||
| const int expecteddof = dofindices.size() > 0 ? (int)dofindices.size() : GetDOF(); | ||
| OPENRAVE_ASSERT_OP_FORMAT((int)dof, >=, expecteddof, | ||
| "env=%s, body '%s' not enough values %d<%d", GetEnv()->GetNameId() % GetName() % dof % expecteddof, | ||
| ORE_InvalidArguments); | ||
|
|
||
| GetDOFValues(_vTempJoints); | ||
| if( dofindices.size() > 0 ) { | ||
| // user only set a certain number of indices, so have to fill the temporary array with the full set of values first | ||
| // and then overwrite with the user set values | ||
| for(size_t i = 0; i < dofindices.size(); ++i) { | ||
| if( !std::isnan(pJointValues[i]) ) { | ||
| // When dofindices covers every dof of the body and the input has no NaN, every element of _vTempJoints gets | ||
| // overwritten, so can skip the expensive GetDOFValues. To check the coverage, pre-fill _vTempJoints with NaN | ||
| // before writing the input values into it. If no NaN remains, all dofs were covered. | ||
| bool bNeedCurrentValues = ((int)dofindices.size() != GetDOF()); | ||
| if( !bNeedCurrentValues ) { | ||
| for(int i = 0; i < expecteddof; ++i) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Puttichai we should also becareful that dofindices doesn't have repeated indices. at the very least we have to assert if you don't think this is a valid input |
||
| if( std::isnan(pJointValues[i]) ) { | ||
| bNeedCurrentValues = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| if( !bNeedCurrentValues ) { | ||
| _vTempJoints.assign(GetDOF(), std::numeric_limits<dReal>::quiet_NaN()); | ||
| for(size_t i = 0; i < dofindices.size(); ++i) { | ||
| _vTempJoints.at(dofindices[i]) = pJointValues[i]; | ||
| } | ||
| for(const dReal dofvalue : _vTempJoints) { | ||
| if( std::isnan(dofvalue) ) { | ||
| // dofindices has duplicates, so some dof was not covered. Need current values after all. | ||
| bNeedCurrentValues = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| if( bNeedCurrentValues ) { | ||
| // user only set a certain number of indices, so have to fill the temporary array with the full set of values first | ||
| // and then overwrite with the user set values | ||
| GetDOFValues(_vTempJoints); | ||
| for(size_t i = 0; i < dofindices.size(); ++i) { | ||
| if( !std::isnan(pJointValues[i]) ) { | ||
| _vTempJoints.at(dofindices[i]) = pJointValues[i]; | ||
| } | ||
| } | ||
| } | ||
| pJointValues = &_vTempJoints[0]; | ||
| } | ||
| else { | ||
| for(size_t i = 0; i < _vTempJoints.size(); ++i) { | ||
| if( !std::isnan(pJointValues[i]) ) { | ||
| _vTempJoints[i] = pJointValues[i]; | ||
| // When setting values to all joints, the input pJointValues already holds every value so use it directly and | ||
| // skip the expensive GetDOFValues. Only when pJointValues contains NaN (meaning "keep the current value") do we | ||
| // fetch the current values and fill in the rest. | ||
| _vTempJoints.resize(expecteddof); // still need resizing because it may be used under checklimits != CLA_Nothing | ||
| bool bHasNaN = false; | ||
| for(int i = 0; i < expecteddof; ++i) { | ||
| if( std::isnan(pJointValues[i]) ) { | ||
| bHasNaN = true; | ||
| break; | ||
| } | ||
| } | ||
| if( bHasNaN ) { | ||
| GetDOFValues(_vTempJoints); | ||
| for(int i = 0; i < expecteddof; ++i) { | ||
| if( !std::isnan(pJointValues[i]) ) { | ||
| _vTempJoints[i] = pJointValues[i]; | ||
| } | ||
| } | ||
| pJointValues = &_vTempJoints[0]; | ||
| } | ||
| } | ||
| pJointValues = &_vTempJoints[0]; | ||
|
|
||
| if( checklimits != CLA_Nothing ) { | ||
| dReal* ptempjoints = &_vTempJoints[0]; | ||
|
|
||
Oops, something went wrong.
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.
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.
@Puttichai I wonder if there could be another fast path where dofindices.size() == expecteddof, and dofinidces contains all the indices of the robot (even if they are in a different order).
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 see. Thank you for the suggestion. I made a change to skip
GetDOFValueswhendofindicesalready covers all dofs. Also updated test cases.