Skip to content

Commit 06e2a85

Browse files
Dustin Shahidehpourmeta-codesync[bot]
authored andcommitted
Use cmd_args
Summary: Refactors `get_framework_linker_args` and `_get_unchecked_framework_linker_args` to return `cmd_args` instead of `list[str]`, and uses `cmd_args(format=)` for library linker flags. This avoids intermediate list allocations and leverages `cmd_args` composability — the unchecked path collapses from a loop with two appends per framework into a single `cmd_args(framework_names, prepend="-framework")`. To measure the memory usage I ran: ``` $ buck2 kill $ buck2 audit providers igios-no-extensions fbios-no-extensions --quiet $ buck2 debug allocator-stats ``` Memory impact (jemalloc stats, before vs after): - `allocated` is essentially unchanged (+31 MiB / +0.08% out of ~39 GiB), so the real heap footprint didn't move. - `resident` (RSS) dropped by 1.6 GiB (-3.4%), from 47.6 GiB to 46.0 GiB, due to jemalloc's background purge thread reclaiming dirty pages more effectively. - `retained` grew by 1.5 GiB (+5.9%), which is the mirror image — jemalloc kept the virtual address space mappings but released the physical pages back to the OS. This is free on 64-bit and allows cheap reuse without new mmap syscalls. - `active / allocated` ratio (fragmentation) is stable at ~1.13x in both cases. Overall: neutral to slightly positive. No regression in allocation pressure, improved RSS, no concerning tradeoffs. Reviewed By: rmaz Differential Revision: D92996049 fbshipit-source-id: 04e9fa2234b9c144fd9e0ccb4dac0e12a0f9f9c3
1 parent c2f4f74 commit 06e2a85

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

prelude/apple/apple_framework_versions.bzl

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ def validate_sdk_frameworks(frameworks: list[str]) -> None:
11291129
if framework_name not in FRAMEWORK_INTRODUCED_VERSIONS:
11301130
fail("Framework {} is missing version information".format(framework_name))
11311131

1132-
def get_framework_linker_args(ctx: AnalysisContext, framework_names: list[str]) -> list[str]:
1132+
def get_framework_linker_args(ctx: AnalysisContext, framework_names: list[str]) -> cmd_args:
11331133
if not has_apple_toolchain(ctx):
11341134
return _get_unchecked_framework_linker_args(framework_names)
11351135

@@ -1145,7 +1145,7 @@ def get_framework_linker_args(ctx: AnalysisContext, framework_names: list[str])
11451145
if sdk_name.endswith("simulator"):
11461146
sdk_name = sdk_name[:-len("simulator")] + "os"
11471147

1148-
args = []
1148+
args = cmd_args()
11491149
for name in framework_names:
11501150
versions = FRAMEWORK_INTRODUCED_VERSIONS.get(name, None)
11511151
if versions:
@@ -1156,24 +1156,19 @@ def get_framework_linker_args(ctx: AnalysisContext, framework_names: list[str])
11561156
fail(message)
11571157

11581158
if _version_is_greater_than(introduced, deployment_target):
1159-
args.append("-weak_framework")
1159+
args.add("-weak_framework")
11601160
else:
1161-
args.append("-framework")
1161+
args.add("-framework")
11621162
else:
11631163
# Assume this is a non-SDK framework
1164-
args.append("-framework")
1164+
args.add("-framework")
11651165

1166-
args.append(name)
1166+
args.add(name)
11671167

11681168
return args
11691169

1170-
def _get_unchecked_framework_linker_args(framework_names: list[str]) -> list[str]:
1171-
args = []
1172-
for f in framework_names:
1173-
args.append("-framework")
1174-
args.append(f)
1175-
1176-
return args
1170+
def _get_unchecked_framework_linker_args(framework_names: list[str]) -> cmd_args:
1171+
return cmd_args(framework_names, prepend = "-framework")
11771172

11781173
def _version_is_greater_than(x: (int, int, int), y: (int, int, int)) -> bool:
11791174
return x[0] > y[0] or (x[0] == y[0] and x[1] > y[1]) or (x[0] == y[0] and x[1] == y[1] and x[2] > y[2])

prelude/apple/apple_frameworks.bzl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ def _get_apple_frameworks_linker_flags(ctx: AnalysisContext, linkables: list[[Fr
6262
expanded_frameworks_paths = _expand_sdk_framework_paths(ctx, unresolved_framework_paths)
6363
flags = _get_framework_search_path_flags(expanded_frameworks_paths)
6464
flags.add(get_framework_linker_args(ctx, framework_names))
65-
66-
for library in libraries:
67-
flags.add("-l" + _library_name(library))
65+
flags.add(cmd_args([_library_name(library) for library in libraries], format = "-l{}"))
6866

6967
return flags
7068

0 commit comments

Comments
 (0)