Uh oh!
There was an error while loading. Please reload this page.
perf(devx): hoist findEscapingPackages() out of unionInto's per-declaration loop - #9000
Merged
Merged
Conversation
…ration loop check-cross-package-test-inputs.mjs --union-into (Layer A, the CI PR path) called findEscapingPackages() -- a full packages/apps/examples walk that reads every *.test.* file -- once per declared radius the diff touched. The result does not vary between iterations, so index it once into a name -> dir map before the loop instead of re-walking per match. No behaviour change: nothing between the old and new call site mutates packages/apps/examples, and the final output is identical (see PR body for the before/after diff). Fixes#8900 _Generated by [Claude Code](https://claude.ai/code/session_011RB4waLuNbdruCo6X9oobm)_
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
os-project-manager
marked this pull request as ready for review
August 16, 2026 05:22
os-project-manager
enabled auto-merge
August 16, 2026 05:22
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Aug 16, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes#8900
What
check-cross-package-test-inputs.mjs'sunionInto()(Layer A — theturbo ls --affectedunion that runs on the CI PR path) calledfindEscapingPackages()— a full
packages//apps//examples/walk that reads every*.test.*fileit finds — once per declared radius the diff touched, inside the
per-declaration loop.
findEscapingPackages()takes no arguments and itsanswer does not vary between calls, so this repeated the whole-repo walk once
per matching declaration for nothing.
Fix: index it once into a
name → dirmap before the loop, and look up bynameinside it, instead of re-walking and re-finding per iteration.--verifyand--list-escapeseach callfindEscapingPackages()exactlyonce and are untouched by this PR — only
unionInto's loop changes.Why the hoist is safe (no behaviour change)
Nothing between the old per-iteration call site and the new pre-loop call
site writes to
packages/,apps/orexamples/— the only write inunionIntois the finalwriteFileSync(listPath, ...), which targets theturbo lsJSON output file, not the source tree, and happens after bothcall sites. So the walk sees an identical tree at either point and its
result cannot diverge.
Proof: byte-identical output, old vs new, on a diff that hits multiple declarations
Constructed a synthetic changed-files list that trips 9 of the repo's 12
CROSS_PACKAGE_TEST_INPUTSdeclarations at once (a single-declaration diffcan't distinguish the two implementations — the loop only runs once):
Method: committed the fix first (restore point). Ran the post-fix script
against the synthetic input. Then temporarily overwrote the working-tree
file with the pre-fix content (
git show HEAD~1:scripts/check-cross-package-test-inputs.mjs,via plain
cp, not staged) and ran it against the same input. Restored withgit checkout HEAD -- scripts/check-cross-package-test-inputs.mjs(index andtree both back to the committed fix; confirmed with a
0-linegit diff --stat HEADafterward). Diffed both the mutatedturbo-ls.jsonand stdout, old vs new, byte-for-byte:
stdout (identical both runs):
Two more cases, same method, both also byte-identical:
README.md) — same"No cross-package scan..."stdout, same untoucheditemsarray.items(exercises thepresent.has(name) → continuebranch, which neverreaches the lookup) — same stdout, same
itemsarray.Speed, for context (not the acceptance bar — unchanged output is)
Same 9-declaration-hit input, 3 runs each, wall clock:
One stale number, re-derived
The card's own body carries a stale figure (it repeats issue #8900's original
"PR #8899 raises the declaration count from 9 to 12"); the dispatch also
flagged that as possibly stale and asked me to re-derive rather than trust
it. Measured on this PR's base (
main@ab4bb08b, i.e. after #8991):CROSS_PACKAGE_TEST_INPUTShas 12 entries. Doesn't change the fix or itsverification — the loop still runs at most once per declaration either way —
noted only because the card's premise text asked for it to be checked.
Out of scope (left alone, per the dispatch)
--verify/--list-escapescall sites,CROSS_PACKAGE_TEST_INPUTSentries,turbo.json,content/docs/releases/.Tests
pnpm check:cross-package-test-inputs(lint.yml) — self-test (26/26) +--verify:OK: 12 package(s) read outside themselves, all declared, and turbo.json hashes every declared glob.node scripts/check-cross-package-test-inputs.mjs(ci.yml, bare--verifydefault) — sameOKline.pnpm check:nul-bytes(any-edit gate) — green (5943 text file(s)scanned,
0raw control bytes).node scripts/pm/dispatch-gates.mjs scripts/check-cross-package-test-inputs.mjsre-derived against the actual changed path — matches exactly the two named
families above (
check:cross-package-test-inputs[lint.yml],check:cross-package-test-inputs.mjsbare [ci.yml]); no additional familyis implicated by this diff (no test file added/edited, no i18n config
touched).
npx eslint scripts/check-cross-package-test-inputs.mjs --no-inline-config— clean, no findings.
338e27184(git rev-parse --short HEAD), samecommit the gate runs above were taken against.
Changeset
scripts/is not published package source →skip-changesetlabel applied.Generated by Claude Code