Skip to content

Solver performance optimization: selective joint computation#1134

Open
yutingye wants to merge 1 commit into
mainfrom
export-D95663660
Open

Solver performance optimization: selective joint computation#1134
yutingye wants to merge 1 commit into
mainfrom
export-D95663660

Conversation

@yutingye

Copy link
Copy Markdown
Contributor

Summary:
Re-applies the solver optimization idea from D51049715 on the current master.

Currently, SkeletonState computes both transforms and derivatives for all joints during solver evaluations. This is wasteful when only a subset of joints is relevant to the error functions being solved.

This diff adds an optimization to:

  1. Introduce a JointSet type (bitset<1024>) for efficiently tracking sets of joints.

  2. Add getAffectedJoints() virtual method to SkeletonErrorFunctionT that returns which joints are directly used by each error function. Error functions can override this to provide an accurate list (default returns all joints set).

  3. Add an initialize() method to SolverFunctionT that is called once before each solve loop. In SkeletonSolverFunctionT, this pre-computes:

    • activeJointXform_: joints that need transforms (all ancestors of affected joints)
    • activeJointDeriv_: joints that need derivatives (only active ancestors of affected joints)
  4. Add a SkeletonStateT::set() overload that accepts per-joint needXform and needDeriv flags, allowing selective computation.

  5. Add parameter caching in updateSkeletonState() to skip redundant state updates.

  6. Implement getAffectedJoints() for CollisionErrorFunctionT and MarkerErrorFunctionT to provide accurate affected joint lists.

As a side effect, setEnabledParameters() now properly propagates to all error functions at the beginning of each solve via initialize(), fixing a long-standing issue where downstream callers had to ensure setEnabledParameters() was called after all error functions were added.

Differential Revision: D95663660

Summary:
Re-applies the solver optimization idea from D51049715 on the current master.

Currently, SkeletonState computes both transforms and derivatives for all joints during solver evaluations. This is wasteful when only a subset of joints is relevant to the error functions being solved.

This diff adds an optimization to:

1. Introduce a `JointSet` type (bitset<1024>) for efficiently tracking sets of joints.

2. Add `getAffectedJoints()` virtual method to `SkeletonErrorFunctionT` that returns which joints are directly used by each error function. Error functions can override this to provide an accurate list (default returns all joints set).

3. Add an `initialize()` method to `SolverFunctionT` that is called once before each solve loop. In `SkeletonSolverFunctionT`, this pre-computes:
   - `activeJointXform_`: joints that need transforms (all ancestors of affected joints)
   - `activeJointDeriv_`: joints that need derivatives (only active ancestors of affected joints)

4. Add a `SkeletonStateT::set()` overload that accepts per-joint `needXform` and `needDeriv` flags, allowing selective computation.

5. Add parameter caching in `updateSkeletonState()` to skip redundant state updates.

6. Implement `getAffectedJoints()` for `CollisionErrorFunctionT` and `MarkerErrorFunctionT` to provide accurate affected joint lists.

As a side effect, `setEnabledParameters()` now properly propagates to all error functions at the beginning of each solve via `initialize()`, fixing a long-standing issue where downstream callers had to ensure `setEnabledParameters()` was called after all error functions were added.

Differential Revision: D95663660
@meta-codesync

meta-codesync Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

@yutingye has exported this pull request. If you are a Meta employee, you can view the originating Diff in D95663660.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant