Skip to content

Commit

Permalink
fix(builtin): reduce linker debug string allocations (#3309)
Browse files Browse the repository at this point in the history
Construct the formatted strings lazily to prevent allocating and
formatting a string for every transitive dependency.
  • Loading branch information
fmeum authored Feb 2, 2022
1 parent 522fd7c commit fb2eeac
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/linker/link_node_modules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.""",
Expand Down Expand Up @@ -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 ""
Expand All @@ -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,
Expand Down

0 comments on commit fb2eeac

Please sign in to comment.