Skip to content

perf(kinbody): skip redundant GetDOFValues recompute in SetDOFValues#1564

Open
Puttichai wants to merge 11 commits into
productionfrom
optimize_setdofvalues_bookkeeping_2_20260609
Open

perf(kinbody): skip redundant GetDOFValues recompute in SetDOFValues#1564
Puttichai wants to merge 11 commits into
productionfrom
optimize_setdofvalues_bookkeeping_2_20260609

Conversation

@Puttichai

@Puttichai Puttichai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Description

KinBody::SetDOFValues opened with GetDOFValues(_vTempJoints), which reconstructs every joint angle from the current link transforms (a quatMultiply chain + atan2 per DOF — the inverse of the forward kinematics it is about to redo). In the common full-vector path every fetched value is then immediately overwritten by the input, so the recompute is pure waste.

This fills _vTempJoints from the input directly, and only calls GetDOFValues when an input is NaN (the "keep the current value" sentinel). The dofindices and NaN paths are unchanged.

  • Bit-for-bit identical results (111 / 111 scenes)
  • SetDOFValues ~36% faster on average (median 38%, up to 53%)

Unit test: https://tiny.mujin.co.jp/7f4na

Puttichai added 3 commits June 9, 2026 18:26
SetDOFValues opened with GetDOFValues(_vTempJoints), which reconstructs every
joint value from the current link transforms (a quatMultiply chain + atan2 per
DOF, i.e. the inverse of the forward kinematics it is about to perform). In the
common path (full DOF vector, no NaN), every fetched value is then immediately
overwritten by the input, so the recompute is pure waste.

Fill _vTempJoints from the input directly in that path, and only call
GetDOFValues when an input is NaN (the keep-current-value sentinel). The
dofindices and NaN paths are unchanged.
Comment thread src/libopenrave/kinbody.cpp Outdated
Comment thread src/libopenrave/kinbody.cpp Outdated
Comment thread src/libopenrave/kinbody.cpp Outdated
@Puttichai
Puttichai marked this pull request as ready for review July 13, 2026 02:21
Comment thread src/libopenrave/kinbody.cpp Outdated
// 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);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps only resize if bHasNAN?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it too but _vTempJoints may also be used under if( checklimits != CLA_Nothing ) below. I added a comment here to clarify.

ORE_InvalidArguments);

GetDOFValues(_vTempJoints);
if( dofindices.size() > 0 ) {

Copy link
Copy Markdown
Owner

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).

Copy link
Copy Markdown
Collaborator Author

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 GetDOFValues when dofindices already covers all dofs. Also updated test cases.

// 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) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants