From fb2eeacf82d68a5e997e81a932d4eb24da7af5be Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Wed, 2 Feb 2022 19:22:25 +0100 Subject: [PATCH] fix(builtin): reduce linker debug string allocations (#3309) Construct the formatted strings lazily to prevent allocating and formatting a string for every transitive dependency. --- internal/linker/link_node_modules.bzl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/linker/link_node_modules.bzl b/internal/linker/link_node_modules.bzl index dd13265486..c04e109e3b 100644 --- a/internal/linker/link_node_modules.bzl +++ b/internal/linker/link_node_modules.bzl @@ -14,9 +14,9 @@ runtimes to locate all the first-party packages. load("//internal/providers:external_npm_package_info.bzl", "ExternalNpmPackageInfo") load("@rules_nodejs//nodejs:providers.bzl", "LinkablePackageInfo") -def _debug(vars, *args): +def _debug(vars, format, args_tuple): if "VERBOSE_LOGS" in vars.keys(): - print("[link_node_modules.bzl]", *args) + print("[link_node_modules.bzl]", format % args_tuple) LinkerPackageMappingInfo = provider( doc = """Provider capturing package mappings for the linker to consume.""", @@ -194,9 +194,9 @@ def _get_linker_package_mapping_info(target, ctx): # Look for LinkablePackageInfo mapping in this node # LinkablePackageInfo may be provided without a package_name so check for that case as well if not LinkablePackageInfo in target: - _debug(ctx.var, "No LinkablePackageInfo for", target.label) + _debug(ctx.var, "No LinkablePackageInfo for %s", (target.label)) elif not target[LinkablePackageInfo].package_name: - _debug(ctx.var, "No package_name in LinkablePackageInfo for", target.label) + _debug(ctx.var, "No package_name in LinkablePackageInfo for %s", (target.label)) else: linkable_package_info = target[LinkablePackageInfo] 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): link_path = linkable_package_info.path, ), ) - _debug(ctx.var, "target %s (package path: %s) adding module mapping %s: %s" % ( + _debug(ctx.var, "target %s (package path: %s) adding module mapping %s: %s", ( target.label, package_path, linkable_package_info.package_name,