Hi everyone,
I’m coming across a performance issue in HdRenderIndex::RemoveRprim related to HD_ENABLE_SCENE_INDEX_EMULATION on MacOS. Compared with NO emulation, RemoveRprim could be significantly slow especially when removing amount goes to 10k+.
The bottleneck is in SdfPathTable (to be more precious, _Entry::RemoveChild). As this is a very fundamental data structure, this issue could impact many other modules.
Following is a simple way to reproduce this problem with RenderIndex:
const int testAmount = 1 << 16;
const std::string prefix = isFlattened ? "/prim_" : "/root/prim_";
SdfPathVector pathList;
// Prepare data set.
for (int i = 0; i < testAmount; ++i)
{
SdfPath id(prefix + std::to_string(i));
pRenderIndex->InsertRprim(HdPrimTypeTokens->mesh, pSceneDelegate, id);
pathList.push_back(id);
}
pRenderIndex->SyncAll(&tasks, &taskContext);
// Timing block
{
for (int i = 0; i < testAmount; ++i)
pRenderIndex->RemoveRprim(pathList[i]);
}
pRenderIndex->SyncAll(&tasks, &taskContext);
Either with parent node or not could notice this problem. And this is the comparison results with google benchmark (mean of 9 iter) on Mac M2 (4p core + 4e core, 24G mem):
Benchmark(FixtureName/CaseName/testAmount/isFlattened) Ratio Without Simulation(ns) With Simulation(ns)
--------------------------------------------------------------------------------------------------------------------------
HydraFixture/TestRenderIndexRemoval/8/0_mean +0.7676 4432 7835
HydraFixture/TestRenderIndexRemoval/64/0_mean +1.0302 36036 73160
HydraFixture/TestRenderIndexRemoval/512/0_mean +3.5271 222733 1008337
HydraFixture/TestRenderIndexRemoval/4096/0_mean +18.2766 2553746 49227664
HydraFixture/TestRenderIndexRemoval/32768/0_mean +30.6114 81251933 2568485579
HydraFixture/TestRenderIndexRemoval/65536/0_mean +46.4456 235663733 11181215722
HydraFixture/TestRenderIndexRemoval/8/1_mean +0.7398 4527 7877
HydraFixture/TestRenderIndexRemoval/64/1_mean +0.9724 37361 73691
HydraFixture/TestRenderIndexRemoval/512/1_mean +3.6652 220050 1026568
HydraFixture/TestRenderIndexRemoval/4096/1_mean +18.7637 2505614 49520191
HydraFixture/TestRenderIndexRemoval/32768/1_mean +31.1191 80429033 2583304667
HydraFixture/TestRenderIndexRemoval/65536/1_mean +46.6312 236563287 11267796458
Does anyone have any idea? That would be really helpful!
Thank you,
Lumina Wang