Skip to content

ci: component size writes no temp file and measures the import's chunk - #9441

Closed
vjeux wants to merge 1 commit into
meta:mainfrom
vjeux:ci/component-size-no-scratch-file
Closed

vjeux wants to merge 1 commit into
meta:mainfrom
vjeux:ci/component-size-no-scratch-file

Conversation

@vjeux

@vjeux vjeux commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

.github/scripts/lib/component-size.test.mjs times out at 30 s on a loaded machine, while it passes alone in about 2 s.

The PR size report's component measurement wrote a one-line entry file for each import into a fresh directory under the system temp directory, then bundled it with esbuild. The tests also build their fixture trees there.

  • esbuild reads the listing of every directory above each file it bundles, so every build read the temp directory's whole listing.
  • On a shared development machine whose temp directory holds 184,000 entries (mostly test directories left behind), that read costs 140 to 270 ms per build unloaded, and about 2 s with two cores shared by four processes.
  • The build itself takes 5 ms in a directory with a small listing: 5.1 ms under /dev/shm, 6.0 ms inside the repository.

The measurement also took the wrong chunk for four components. Each import() target is an entry point too, and the old lookup took the first entry point in esbuild's outputs. With eight or more import() targets, a target's chunk can come first, so the report counted a lazily loaded chunk (TimestampHoverCard's) in place of the import's own.

Intended invariant

A component's measured size counts the import's own chunk and the chunks it imports statically, and depends only on the import being measured. How long measuring it takes does not depend on what else is in the system temp directory.

Change

  • bundleImportWithInputs gives esbuild the import as stdin, read as if it were a file beside the measured entry (resolveDir), and keeps the outputs in memory. It writes nothing.
  • It finds the import's own chunk as the output whose entry point is the import, instead of the first output with any entry point. This changes four figures in the main record (see Evidence); each now counts the import's own chunk.
  • bundleInputsByEntry keeps its outputs in memory without creating a temp directory for them.
  • The tests build their fixture trees under the repository's node_modules/.cache, so the directories above the measured files are small as well.
  • A new test checks that measuring an import writes no file, and another that an import with eight import() targets is measured by its own chunk.

Evidence

  • Load A/B on a 2-thread pin (one physical core), two busy loops beside it, 4 workers, ten rounds alternating which arm runs first; both arms use a temp directory of 184,000 entries with 16 processes creating and removing small trees in it, as a suite's fixtures do:

    Failed tests i18n import cost (scripts/i18n-english-fallback.test.mjs) component-size.test.mjs :85
    main 4 of 10 runs time out p50 29.4 s, max 66.7 s p50 10.9 s, max 29.6 s
    this branch 0 p50 10.6 s, max 11.3 s p50 0.3 s, max 0.4 s
  • Listings of the temp directory (strace, those two tests once): 9 on main, 0 on this branch.

  • Same-time comparison, pinned to two cores, four copies of the test file in parallel, three rounds, box load 87 to 92:

    • main: 5 of 96 tests failed (timed out); the file took 5.9 s at the median and up to 137 s; the slowest case took 52 s;
    • this branch: 108 of 108 passed; the file took 0.5 s at the median and at most 0.6 s; the slowest case took 0.29 s.
  • Sizes, the whole main record (analyze-pr.js --main-record, 232 components, old lookup and new on the same built tree; the old one gives the same record on a second run): 228 figures are unchanged. Four change, each to the import's own chunk:

    Component gzip JavaScript, before → after gzip CSS, before → after
    ContextMenuItem (core; measured through the package entry) 53,875 → 19,577 B 10,137 → 5,716 B
    Chart (charts) 64,413 → 133,664 B 20 → 494 B
    ChartLegend (charts) 53,665 → 34,779 B 20 → 224 B
    ChartTooltip (charts) 53,670 → 102,303 B 20 → 423 B

    Before, each of the four took TimestampHoverCard's lazily loaded chunk as the import's own. Six other real Core entries (Button, Tooltip, Dialog, TextInput, ProgressBar, DateInput) give byte-identical sizes; measuring them took 0.4 s instead of 4.1 s on the shared machine above.

  • Failure before the change: with main's measurement, "writes no file to measure an import" fails (mkdtempSync was called), and "measures the import's own chunk when an import() target's chunk comes first" fails: the figure is a lazily loaded module's chunk.

  • Success after the change: the file passes 10 of 10, each case in 1 to 100 ms.

  • CI impact: the changed script runs in ci.yml's build-storybook job (the PR report's size measurement in analyze-pr.js) and in deploy.yml's typecheck job (the main record), each on its unchanged runner: ubuntu-latest, standard GitHub-hosted, or 4-core-ubuntu for a dispatched release-check. A fresh hosted runner's temp directory is small, so a measurement takes about as long as before there.

    • Job-minutes per update, runner-pool usage and time to green are unchanged.
    • The test file runs in the Node unit suite on its unchanged runner, in about a second either way.

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

.github/scripts/lib/component-size.test.mjs in the node Vitest project, plus the six-entry size comparison above against a built Core.

Local gates at 12d6491:

  • the file, 9 of 9;
  • Prettier on both files;
  • changeset coverage (nothing ships).

Local gates at 90e86f1, merged with main 1790062:

  • pnpm review:pre: no findings;
  • the file, 10 of 10; the new lookup test fails with main's lookup;
  • the whole main record, old lookup and new (the table above);
  • pnpm build, then pnpm test:node: 16,112 passed, 76 skipped, 0 failed (3,270 files).

The load A/B above ran on ef8f66c, whose measurement code is this head's.

@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 3, 2026 11:46am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 2, 2026
@astracat-bot

astracat-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 3, 2026, 11:57 AM UTC

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 90e86f1

Storybook · Sandbox · built from this PR's head

Current run: The current CI run concluded failure. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The measurement change looks right: sizes come out identical and the new test pins the no-scratch-file rule. One thing is needed before approval: since this changes a CI script, the description needs the CI impact: line that AST-030 FR19 and the maintenance template ask for (runner class, job-minutes per update, runner-pool usage and time to green, even when all are unchanged).

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The measurement change looks right, and the CI impact: line is now in place; one wording fix is needed before approval.

  • The commit message and the description say measured sizes are unchanged, but ContextMenuItem (an alias measured through the package entry) moves from 53,875 to 19,577 B gzip JavaScript and from 10,137 to 5,716 B gzip CSS, because the new entry-chunk lookup no longer picks the lazily loaded TimestampHoverCard chunk; please say so in both.

Optional: a fixture whose lazily loaded module is the first entry output would pin that fix, and the CI impact: line could also name deploy.yml's typecheck job, which runs the same script on main pushes.

[Automated review]

.join('/');
const entryOutput = Object.keys(outputs).find(
key => outputs[key].entryPoint !== undefined,
key => outputs[key].entryPoint === entryPoint,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lookup also changes one measured figure. ContextMenuItem is an alias, so it is measured through the package entry, where the old lookup took the lazily loaded TimestampHoverCard chunk (53,875 B gzip JavaScript); this takes the import's own chunk (19,577 B). The new figure is right; the description and the commit message should say that this component's size changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 90e86f1. The full main record (232 components, old and new lookup on the same build) shows four figures change, each to the import's own chunk: ContextMenuItem, Chart, ChartLegend and ChartTooltip. The commit message and the description list them; the other 228 are unchanged. With eight or more import() targets, a target's chunk comes first in esbuild's outputs; a new test with eight targets fails on the old lookup. The CI impact line names deploy.yml's typecheck job too.

The PR report's component size measurement wrote a one-line entry file
for each import into a fresh directory under the system temp directory,
and bundled it with esbuild. esbuild reads the listing of every
directory above each file it bundles, so every measurement read the
temp directory's listing. On a shared machine whose temp directory holds
184,000 entries, that read took 140 to 270 ms per build unloaded, and
about 2 s with two cores shared by four processes; the build itself
takes 5 ms. component-size.test.mjs runs ten such builds, and timed out
at 30 s on a loaded machine.

The entry now reaches esbuild as stdin, read as if it were a file beside
the measured entry, and the outputs stay in memory: nothing is written.
The tests keep their fixture trees under the repository's
node_modules/.cache, so the directories above the measured files are
small too.

The import's own chunk is now the output whose entry point is the
import. Each import() target is an entry point too, and the old lookup
took the first entry point in esbuild's outputs. With eight or more
import() targets, a target's chunk can come first. So four figures in
the main record change, each to the import's own chunk: ContextMenuItem
(19,577 B of gzip JavaScript, from 53,875), Chart (133,664, from
64,413), ChartLegend (34,779, from 53,665) and ChartTooltip (102,303,
from 53,670). The other 228 components' figures are unchanged.
@vjeux
vjeux force-pushed the ci/component-size-no-scratch-file branch from ef8f66c to 90e86f1 Compare November 3, 2026 11:38
@vjeux vjeux changed the title ci: component size measurement writes no scratch file in the system temp directory ci: component size writes no temp file and measures the import's chunk Nov 3, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ready to approve: the measurement no longer touches the system temp directory, the new import-chunk lookup is right, and the description and commit message now name the four figures that move (ContextMenuItem, Chart, ChartLegend, ChartTooltip); the other 228 of 232 are unchanged. Both new tests fail against the old measurement and pass with this change.

Optional: the CI impact: line gives the runners as ubuntu-latest or 4-core-ubuntu, but deploy.yml's typecheck job runs on ubuntu-24.04-arm; it is still a standard GitHub-hosted runner, so only the label is off.

[Automated review]

@vjeux

vjeux commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Re-landed as #9778 (47790d3), which keeps this change's hunks. Closing in its favor. Thanks!

@vjeux vjeux closed this Nov 4, 2026
@vjeux
vjeux deleted the ci/component-size-no-scratch-file branch November 4, 2026 07:45

This branch was successfully deployed

1 active deployment
Preview — 90e86f13 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant