From 5eda7430c51cd09ca6f34c04413326968d1bb02f Mon Sep 17 00:00:00 2001 From: Amirzhan Idryshev Date: Fri, 24 Jan 2025 06:33:32 -0800 Subject: [PATCH] Optimise peak memory usage [3/4] Summary: **Why?** Running analysis for multiple targets quickly increases the memory usage by buck2 daemon. Because of that glean indexing [bxl script](https://www.internalfb.com/code/fbsource//fbcode/glean/facebook/lang/clang/index.bxl) ooms sandcastle machines in some cases. The common issue is very high peak memory usage with a lot of allocations which are [not released immediately](https://fb.workplace.com/groups/starlark/permalink/1312921066063385/). This change is to not create a lambda function in for loop as it allocates a lot of memory Reviewed By: malanka, podtserkovskiy Differential Revision: D68555017 fbshipit-source-id: 6802bf0095730a056232ba80b480f1c4216e2943 --- prelude/cxx/groups.bzl | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/prelude/cxx/groups.bzl b/prelude/cxx/groups.bzl index 9c3b7a9dc5e71..bf0c7629a5831 100644 --- a/prelude/cxx/groups.bzl +++ b/prelude/cxx/groups.bzl @@ -16,7 +16,6 @@ load( "@prelude//utils:graph_utils.bzl", "depth_first_traversal_by", ) -load("@prelude//utils:lazy.bzl", "lazy") load( "@prelude//utils:strings.bzl", "strip_prefix", @@ -269,13 +268,17 @@ def _find_targets_in_mapping( def populate_matching_targets(node): # Label -> bool: graph_node = graph_map[node] - if not mapping.filters or lazy.is_all(lambda filter: filter.matches(node, graph_node.labels), mapping.filters): - matching_targets[node] = None - if mapping.traversal == Traversal("tree"): - # We can stop traversing the tree at this point because we've added the - # build target to the list of all targets that will be traversed by the - # algorithm that applies the groups. - return False + if mapping.filters: + for filter in mapping.filters: + if not filter.matches(node, graph_node.labels): + return True + + matching_targets[node] = None + if mapping.traversal == Traversal("tree"): + # We can stop traversing the tree at this point because we've added the + # build target to the list of all targets that will be traversed by the + # algorithm that applies the groups. + return False return True def populate_matching_targets_bfs_wrapper(node): # (Label) -> list