Skip to content

Conversation

@sssooonnnggg
Copy link
Contributor

Optimize the performance of constructing prims, avoiding too frequent reallocation of the children vector.

@syoyo
Copy link
Collaborator

syoyo commented Aug 23, 2024

How much the performance will be improved with this PR?

@sssooonnnggg
Copy link
Contributor Author

sssooonnnggg commented Aug 26, 2024

I used tusdcat to profile a release build using the Visual Studio built-in profiler.
Without this optimization:
image
With this optimization:
image

CPU usage by USDCReader::Impl::ReconstructPrimRecursively decreased rom 51% to 36%.

usdc file for testing:
USDExportedPkg.resources.zip

@syoyo syoyo requested a review from Copilot May 9, 2025 02:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR aims to optimize performance by reserving memory for prim children to reduce frequent vector reallocations.

  • Added a conditional check on currPrimPtr and reserved the necessary capacity based on the number of children.

const crate::CrateReader::Node &node = _nodes[size_t(current)];
DCOUT("node.Children.size = " << node.GetChildren().size());
if (currPrimPtr) {
currPrimPtr->children().reserve(node.GetChildren().size());
Copy link

Copilot AI May 9, 2025

Choose a reason for hiding this comment

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

Consider caching node.GetChildren().size() in a local variable before both reserving and iterating over the children to avoid multiple function calls.

Copilot uses AI. Check for mistakes.
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