Skip to content

Conversation

@adamfidel
Copy link
Member

When invoking auto g = graph.finalize() on a graph with a moderate amount of nodes, duplicating the nodes of the modifiable graph into the executable graph takes a non-trivial amount of time. This PR introduces a few changes to improve the performance of duplicateNodes():

  1. Replace the std::dequeue with a std::vector so that it can be directly moved, omitting unnecessary O(n) allocations
  2. Keep track of whether there are any subgraphs in the first pass of the graph and skip the second pass of the graph if there are no subgraphs
  3. Add a reserve() for the vector of nodes and map that we are going to create, since we know the total number of nodes.

Note that 1. optimizes the fast path when the graph does not contain a subgraph, but will likely make finalize slower for graphs that contain subgraphs.

The changes for 2. make the diff seem much larger than it actually is, but the majority of it is whitespace from moving the subgraph handling into an if statement.

@adamfidel adamfidel requested a review from a team as a code owner November 4, 2025 15:31
@adamfidel adamfidel requested a review from reble November 4, 2025 15:31
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.

1 participant