diff --git a/src/tint/resolver/dependency_graph.cc b/src/tint/resolver/dependency_graph.cc index 2ddcaaa0fd..6dd35a50ec 100644 --- a/src/tint/resolver/dependency_graph.cc +++ b/src/tint/resolver/dependency_graph.cc @@ -489,6 +489,10 @@ struct DependencyAnalysis { /// #diagnostics. /// @returns true if analysis found no errors, otherwise false. bool Run(const ast::Module& module) { + // Reserve container memory + graph_.resolved_symbols.reserve(module.GlobalDeclarations().Length()); + sorted_.reserve(module.GlobalDeclarations().Length()); + // Collect all the named globals from the AST module GatherGlobals(module); diff --git a/src/tint/utils/unique_vector.h b/src/tint/utils/unique_vector.h index 0f3f18d8a1..d4018b247c 100644 --- a/src/tint/utils/unique_vector.h +++ b/src/tint/utils/unique_vector.h @@ -93,6 +93,13 @@ struct UniqueVector { /// @returns a const reference to the internal vector operator const std::vector&() const { return vector; } + /// Pre-allocates `count` elements in the vector and set + /// @param count the number of elements to pre-allocate + void reserve(size_t count) { + vector.reserve(count); + set.reserve(count); + } + /// Removes the last element from the vector /// @returns the popped element T pop_back() {