Skip to content

Commit

Permalink
Optimise peak memory usage [3/4]
Browse files Browse the repository at this point in the history
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
  • Loading branch information
iamirzhan authored and facebook-github-bot committed Jan 24, 2025
1 parent c473bd9 commit 5eda743
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions prelude/cxx/groups.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5eda743

Please sign in to comment.