Skip to content

Commit 427b524

Browse files
authored
perf: avoid AST depth depending on pnpm workspace size (#2865)
This converts 2 `if/elif bazel_package == "pnpm-project-path"` blocks into 2 constants and the `if/elif` is replaced with a lookup into the constant. See the diffs of the snapshot files for the best outline of the changes. This prevents a reported `java.lang.StackOverflowError` from the bazel starlark parser treating `elif` as nested `else: if`. This reduces the `npm_link_all_packages()` from N `if/elif` statements into a single map lookup. The tradeoff is when the generated `defs.bzl` is `load()`ed it now has 2 giant maps declared at load time. Overall I (and my robot assistants, and my testing on a repo with ~2k pnpm workspace projects) think this has negligible impact on actually performance but should avoid the `java.lang.StackOverflowError`. ### Changes are visible to end-users: no ### Test plan - Covered by existing test cases
1 parent 9350244 commit 427b524

13 files changed

Lines changed: 2733 additions & 2472 deletions

File tree

.aspect/config.axl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ buildifier = format.alias(
4444
"**/*.bzl",
4545
"**/*.star",
4646
],
47+
"exclude_patterns": [
48+
"**/snapshots/**",
49+
],
4750
},
4851
summary = "Format Starlark files using buildifier.",
4952
)

e2e/npm_translate_lock_disable_hooks/snapshots/defs.bzl

Lines changed: 24 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/npm_translate_lock_empty/snapshots/npm_defs.bzl

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/npm_translate_lock_replace_packages/snapshots/npm_defs.bzl

Lines changed: 29 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)