Skip to content

Commit fb2eeac

Browse files
authored
fix(builtin): reduce linker debug string allocations (#3309)
Construct the formatted strings lazily to prevent allocating and formatting a string for every transitive dependency.
1 parent 522fd7c commit fb2eeac

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

internal/linker/link_node_modules.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ runtimes to locate all the first-party packages.
1414
load("//internal/providers:external_npm_package_info.bzl", "ExternalNpmPackageInfo")
1515
load("@rules_nodejs//nodejs:providers.bzl", "LinkablePackageInfo")
1616

17-
def _debug(vars, *args):
17+
def _debug(vars, format, args_tuple):
1818
if "VERBOSE_LOGS" in vars.keys():
19-
print("[link_node_modules.bzl]", *args)
19+
print("[link_node_modules.bzl]", format % args_tuple)
2020

2121
LinkerPackageMappingInfo = provider(
2222
doc = """Provider capturing package mappings for the linker to consume.""",
@@ -194,9 +194,9 @@ def _get_linker_package_mapping_info(target, ctx):
194194
# Look for LinkablePackageInfo mapping in this node
195195
# LinkablePackageInfo may be provided without a package_name so check for that case as well
196196
if not LinkablePackageInfo in target:
197-
_debug(ctx.var, "No LinkablePackageInfo for", target.label)
197+
_debug(ctx.var, "No LinkablePackageInfo for %s", (target.label))
198198
elif not target[LinkablePackageInfo].package_name:
199-
_debug(ctx.var, "No package_name in LinkablePackageInfo for", target.label)
199+
_debug(ctx.var, "No package_name in LinkablePackageInfo for %s", (target.label))
200200
else:
201201
linkable_package_info = target[LinkablePackageInfo]
202202
package_path = linkable_package_info.package_path if hasattr(linkable_package_info, "package_path") else ""
@@ -207,7 +207,7 @@ def _get_linker_package_mapping_info(target, ctx):
207207
link_path = linkable_package_info.path,
208208
),
209209
)
210-
_debug(ctx.var, "target %s (package path: %s) adding module mapping %s: %s" % (
210+
_debug(ctx.var, "target %s (package path: %s) adding module mapping %s: %s", (
211211
target.label,
212212
package_path,
213213
linkable_package_info.package_name,

0 commit comments

Comments
 (0)