Skip to content

Commit caace83

Browse files
committed
perf(vtkviewport): speedup getViewPropsWithNestedProps
Avoid using filter() and includes() that are slow operations. issue #3351
1 parent 8ecd009 commit caace83

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Sources/Rendering/Core/Viewport/index.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,23 @@ function vtkViewport(publicAPI, model) {
4848

4949
publicAPI.getViewPropsWithNestedProps = () => {
5050
let allPropsArray = [];
51-
// Handle actor2D instances separately so that they can be overlayed and layered
52-
const actors2D = publicAPI.getActors2D();
53-
// Sort the actor2D list using its layer number
54-
actors2D.sort((a, b) => a.getLayerNumber() - b.getLayerNumber());
55-
// Filter out all the actor2D instances
56-
const newPropList = model.props.filter((item) => !actors2D.includes(item));
57-
for (let i = 0; i < newPropList.length; i++) {
58-
gatherProps(newPropList[i], allPropsArray);
51+
// Repopulate the actor2D list to minimize browsing operations.
52+
model.actors2D = [];
53+
for (let i = 0; i < model.props.length; i++) {
54+
// Handle actor2D instances separately so that they can be overlayed and layered
55+
const isActor2D = model.props[i].getActors2D();
56+
if (isActor2D && (!Array.isArray(isActor2D) || isActor2D.length > 0)) {
57+
model.actors2D = model.actors2D.concat(isActor2D);
58+
} else {
59+
gatherProps(model.props[i], allPropsArray);
60+
}
5961
}
62+
// Actor2D must be rendered by layer number order
63+
model.actors2D.sort((a, b) => a.getLayerNumber() - b.getLayerNumber());
6064
// Finally, add the actor2D props at the end of the list
6165
// This works because, when traversing the render pass in vtkOpenGLRenderer, the children are
6266
// traversed in the order that they are added to the list
63-
allPropsArray = allPropsArray.concat(actors2D);
67+
allPropsArray = allPropsArray.concat(model.actors2D);
6468
return allPropsArray;
6569
};
6670

0 commit comments

Comments
 (0)