Skip to content

Commit 92526e3

Browse files
authored
perf: reduce per-action overhead registering NpmPackageExtract (#2910)
Build the tar argument list with a single add_all call, hoist the constant execution_requirements dict, and skip the --exclude pass when exclude_package_contents is empty. The rendered command line is unchanged. ### Changes are visible to end-users: no ### Test plan - Covered by existing test cases
1 parent d82417a commit 92526e3

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

npm/private/npm_package_store.bzl

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ _SUPPORTS_SYMLINK_TARGET_TYPE = bazel_features.rules.symlink_action_has_target_t
1414

1515
_PACKAGE_STORE_PREFIX_LEN = len("node_modules/{}/".format(utils.package_store_root))
1616

17+
_EXTRACT_EXECUTION_REQUIREMENTS = {
18+
"supports-path-mapping": "1",
19+
}
20+
1721
_DOC = """Defines a npm package that is linked into a node_modules tree.
1822
1923
The npm package is linked with a pnpm style symlinked node_modules output tree.
@@ -245,13 +249,22 @@ def _npm_package_store_impl(ctx):
245249
bsdtar = ctx.toolchains[tar_lib.toolchain_type]
246250

247251
args = ctx.actions.args()
248-
args.add("--extract")
249-
args.add("--no-same-owner")
250-
args.add("--no-same-permissions")
251-
args.add("--strip-components", "1")
252-
args.add("--file", src)
253-
args.add_all("--directory", [package_store_directory], expand_directories = False)
254-
args.add_all(ctx.attr.exclude_package_contents, before_each = "--exclude")
252+
args.add_all(
253+
[
254+
"--extract",
255+
"--no-same-owner",
256+
"--no-same-permissions",
257+
"--strip-components",
258+
"1",
259+
"--file",
260+
src,
261+
"--directory",
262+
package_store_directory,
263+
],
264+
expand_directories = False,
265+
)
266+
if ctx.attr.exclude_package_contents:
267+
args.add_all(ctx.attr.exclude_package_contents, before_each = "--exclude")
255268

256269
ctx.actions.run(
257270
executable = bsdtar.tarinfo.binary,
@@ -260,9 +273,7 @@ def _npm_package_store_impl(ctx):
260273
arguments = [args],
261274
mnemonic = "NpmPackageExtract",
262275
progress_message = "Extracting npm package {}@{}".format(package, version),
263-
execution_requirements = {
264-
"supports-path-mapping": "1",
265-
},
276+
execution_requirements = _EXTRACT_EXECUTION_REQUIREMENTS,
266277
toolchain = Label("@tar.bzl//tar/toolchain:type"),
267278

268279
# Always override the locale to give better hermeticity.

0 commit comments

Comments
 (0)