Skip to content

Conversation

@cameronwhite
Copy link
Contributor

Description of Change(s)

This became an n^2 loop when there were many inputs with non-overlapping scene roots (e.g. native instancing with a large number of prototypes) and the size of _inputsPathTable approached the number of inputs.

In this scenario the majority of the scene roots are of the form:

  • /UsdNiPropagatedPrototypes/__hash_1__/__Prototype_1/UsdNiInstancer
  • ...
  • /UsdNiPropagatedPrototypes/__hash_N__/__Prototype_1/UsdNiInstancer

We can instead use FindSubtreeRange(sceneRoot) to find which table entries each input should be added to, eliminating the HasPrefix() check against every entry.

Attached is an example scene with 10k prototypes (usdskel_instanced.zip) along before & after stats of time spent in _RebuildInputsPathTable()

Before:

    0.002 ms     0.002 ms       1 samples    |   | pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    0.001 ms     0.001 ms       3 samples    |   |   | pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    0.002 ms     0.002 ms       2 samples    |   |   |   pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    0.001 ms     0.001 ms       2 samples    |   |   pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    6.611 ms     6.611 ms   20000 samples    |   |   |   |   |   |   |   pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
 1958.234 ms  1958.234 ms       1 samples    |   |   |   |   |   |   | pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    0.003 ms     0.003 ms       1 samples    |   |   |   |   pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    0.003 ms     0.003 ms       1 samples    |   |   pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable

After:

    0.002 ms     0.002 ms       1 samples    |   | pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    0.001 ms     0.001 ms       3 samples    |   |   | pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    0.002 ms     0.002 ms       2 samples    |   |   |   pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    0.001 ms     0.001 ms       2 samples    |   |   pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    5.930 ms     5.930 ms   20000 samples    |   |   |   |   |   |   |   pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    5.691 ms     5.691 ms       1 samples    |   |   |   |   |   |   | pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    0.004 ms     0.004 ms       1 samples    |   |   |   |   pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable
    0.002 ms     0.002 ms       1 samples    |   |   pxrInternal_v0_25_8__pxrReserved__::HdMergingSceneIndex::_RebuildInputsPathTable

Link to proposal (if applicable)

Fixes Issue(s)

N/A

Checklist

This became an n^2 loop when there were many inputs with non-overlapping scene
roots (e.g. native instancing with a large number of prototypes) and the
size of _inputsPathTable approached the number of inputs.

In this scenario the majority of the scene roots are of the form:
- /UsdNiPropagatedPrototypes/__hash_1__/__Prototype_1/UsdNiInstancer
...
- /UsdNiPropagatedPrototypes/__hash_N__/__Prototype_1/UsdNiInstancer

We can instead use FindSubtreeRange(sceneRoot) to directly find which
table entries each input should be added to, eliminating the HasPrefix()
check against every entry.

For a test scene with native instancing (17500 prototypes), this reduced
the overall time spent in _RebuildInputsPathTable() from around 5.5s to 18ms.
@jesschimein
Copy link
Collaborator

Filed as internal issue #USD-11281

(This is an automated message. See here for more information.)

@cameronwhite
Copy link
Contributor Author

This can be closed since 9f005c1 made the same change

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