Skip to content

Commit

Permalink
perf: reduce concatenation, use of .extends
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Aug 21, 2024
1 parent 99d0900 commit c343d69
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions e2e/pnpm_lockfiles/v54/snapshots/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions e2e/pnpm_lockfiles/v60/snapshots/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions e2e/pnpm_lockfiles/v61/snapshots/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions e2e/pnpm_lockfiles/v90/snapshots/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions js/private/js_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -522,16 +522,16 @@ def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [],
bash_launcher, toolchain_files = _bash_launcher(ctx, nodeinfo, entry_point_path, log_prefix_rule_set, log_prefix_rule, fixed_args, fixed_env, is_windows)
launcher = create_windows_native_launcher_script(ctx, bash_launcher) if is_windows else bash_launcher

launcher_files = [bash_launcher]
launcher_files.extend(toolchain_files)
launcher_files = [bash_launcher] + toolchain_files
if hasattr(nodeinfo, "node"):
if nodeinfo.node:
launcher_files.append(nodeinfo.node)
else:
# TODO(3.0): drop support for deprecated toolchain attributes
launcher_files.extend(nodeinfo.tool_files)
launcher_files += nodeinfo.tool_files

launcher_files.extend(ctx.files._node_patches_files + [ctx.file._node_patches])
launcher_files += ctx.files._node_patches_files
launcher_files.append(ctx.file._node_patches)
transitive_launcher_files = None
if ctx.attr.include_npm:
if hasattr(nodeinfo, "npm_sources"):
Expand All @@ -540,7 +540,7 @@ def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [],
# TODO(3.0): drop support for deprecated toolchain attributes
if not hasattr(nodeinfo, "npm_files"):
fail("include_npm requires a minimum @rules_nodejs version of 5.7.0")
launcher_files.extend(nodeinfo.npm_files)
launcher_files += nodeinfo.npm_files

runfiles = gather_runfiles(
ctx = ctx,
Expand Down
7 changes: 5 additions & 2 deletions js/private/js_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,12 @@ def gather_runfiles(
for target in data:
transitive_files_depsets.append(target[DefaultInfo].files)

# Avoid concatenating more then once
data_deps = data + deps

# Gather files from JsInfo providers of data & deps
transitive_files_depsets.append(gather_files_from_js_infos(
targets = data + deps,
targets = data_deps,
include_sources = include_sources,
include_types = include_types,
include_transitive_sources = include_transitive_sources,
Expand All @@ -209,7 +212,7 @@ def gather_runfiles(
transitive_files = depset(transitive = transitive_files_depsets),
).merge_all([
target[DefaultInfo].default_runfiles
for target in data + deps
for target in data_deps
])

LOG_LEVELS = {
Expand Down
12 changes: 6 additions & 6 deletions npm/private/npm_translate_lock_generate.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ def npm_link_all_packages(name = "node_modules", imported_links = []):
for link_fn in imported_links:
new_link_targets, new_scope_targets = link_fn(name)
link_targets.extend(new_link_targets)
link_targets += new_link_targets
for _scope, _targets in new_scope_targets.items():
if _scope not in scope_targets:
scope_targets[_scope] = []
scope_targets[_scope].extend(_targets)
scope_targets[_scope] += _targets
""".format(
defs_bzl_file = "@{}//:{}".format(rctx.name, rctx.attr.defs_bzl_filename),
link_packages_comma_separated = "\"'\" + \"', '\".join(_LINK_PACKAGES) + \"'\"" if len(link_packages) else "\"\"",
Expand Down Expand Up @@ -346,7 +346,7 @@ def npm_link_all_packages(name = "node_modules", imported_links = []):

if len(stores_bzl) > 0:
npm_link_all_packages_bzl.append(""" if is_root:""")
npm_link_all_packages_bzl.extend(stores_bzl)
npm_link_all_packages_bzl += stores_bzl

if len(links_bzl) > 0:
npm_link_all_packages_bzl.append(""" if link:""")
Expand All @@ -356,7 +356,7 @@ def npm_link_all_packages(name = "node_modules", imported_links = []):
els = "" if first_link else "el",
pkg = link_package,
))
npm_link_all_packages_bzl.extend(bzl)
npm_link_all_packages_bzl += bzl
first_link = False

if len(links_targets_bzl) > 0:
Expand All @@ -367,7 +367,7 @@ def npm_link_all_packages(name = "node_modules", imported_links = []):
els = "" if first_link else "el",
pkg = link_package,
))
npm_link_targets_bzl.extend(bzl)
npm_link_targets_bzl += bzl
first_link = False

for fp_link in fp_links.values():
Expand Down Expand Up @@ -470,7 +470,7 @@ def npm_link_all_packages(name = "node_modules", imported_links = []):
other_statements.append(content)
rctx_files[filename] = load_statements + rctx_files[filename] + other_statements
else:
rctx_files[filename].extend(contents)
rctx_files[filename] += contents

if not rctx.attr.bzlmod:
rctx_files[rctx.attr.repositories_bzl_filename] = _generate_repositories(
Expand Down
4 changes: 2 additions & 2 deletions npm/private/npm_translate_lock_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _gather_values_from_matching_names(additive, keyed_lists, *names):
v = keyed_lists[name]
if additive:
if type(v) == "list":
result.extend(v)
result += v
elif type(v) == "string":
result.append(v)
else:
Expand Down Expand Up @@ -352,7 +352,7 @@ ERROR: can not apply both `pnpm.patchedDependencies` and `npm_translate_lock(pat
elif len(translate_patches) > 0:
patches = translate_patches
patch_args, _ = _gather_values_from_matching_names(False, attr.patch_args, "*", name, friendly_name, unfriendly_name)
patches_used.extend(patches_keys)
patches_used += patches_keys

# Resolve string patch labels relative to the root respository rather than relative to rules_js.
# https://docs.google.com/document/d/1N81qfCa8oskCk5LqTW-LNthy6EBrDot7bdUsjz6JFC4/
Expand Down
4 changes: 2 additions & 2 deletions npm/private/test/snapshots/bzlmod/npm_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions npm/private/test/snapshots/wksp/npm_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c343d69

Please sign in to comment.