Skip to content

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

Merged
cixzhang merged 3 commits into
mainfrom
ci/component-size-import-chunk
Nov 4, 2026
Merged

cixzhang merged 3 commits into
mainfrom
ci/component-size-import-chunk

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Re-lands #9441 by @vjeux verbatim (the same two files, byte-identical to its head 90e86f1), with vjeux as co-author. #9441 closes in favour of this pull request.

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.
  • Re-check on current main (fc68123, Core and Charts built, measureComponentImport called directly with main's lookup and with this one): the same four components move the same way. ContextMenuItem (through the package entry) 26,794 → 20,074 B; Chart 29,026 → 142,032 B; ChartLegend 26,620 → 35,162 B; ChartTooltip 26,616 → 118,792 B of gzip JavaScript. Absolute figures differ from the table above because main has moved since ci: component size writes no temp file and measures the import's chunk #9441's base. No committed baseline or budget holds these figures (the main record is a CI artifact), so nothing else changes.

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.

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.

Co-authored-by: vjeux <[email protected]>
@vercel

vercel Bot commented Nov 3, 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 4, 2026 4:41am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 4, 2026, 4:49 AM UTC

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

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · c2c02f5

Storybook · Sandbox · built from this PR's head

Package size: measured; main has no measurement of the merge base to compare yet.

API changes: none in this pull request

Committed API report behind this build: core 5 rows, theme-butter 1 row, theme-chocolate 1 row, theme-gothic 1 row, theme-matcha 1 row, theme-neutral 1 row, theme-stone 1 row, theme-y2k 1 row; run pnpm api:report.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.

CI impact: 0 job-min per update · pool 0% · time to green −5 min · standard runners · 2 CI action or script files changed (not measured)
Before After Change
Job-minutes per PR update 92.7 92.7 0
Runner pool, runner-minutes a day 32,717 32,717 0 (0%)
Average concurrent jobs 22.7 22.7 0
Time to green (median → this run) 18.9 min 13.9 min −5 min
Runs a day 353 353 0

Not measured (the jobs that use these keep their recent minutes above): .github/scripts/lib/component-size.js, .github/scripts/lib/component-size.test.mjs.

Assumptions: before is each job's average over the last 20 pull-request runs; after keeps that for unchanged jobs and uses this run's minutes for added or changed ones, weighted by how often each changed job ran in those runs; runs a day averages the seven whole days before today; time to green compares this run with the median of those runs that ran the same jobs.


Generated by PR Enrichment workflow | View full report

@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. Measuring a component import no longer writes to the system temp directory, and the new lookup counts the import's own chunk. Both new tests fail against the old measurement and pass with this change. On this head's Core build, only ContextMenuItem changes; the other 102 of 103 figures are identical.

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

[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.

This looks ready to approve. Measuring a component import no longer writes to the system temp directory, and the new lookup counts the import's own chunk; both new tests fail against the old measurement and pass with this change. On this head's Core and Charts build, only ContextMenuItem, Chart, ChartLegend and ChartTooltip change, each to its own chunk.

Optional: the CI impact: line gives deploy.yml's typecheck runner as ubuntu-latest, but that job runs on ubuntu-24.04-arm; both are standard GitHub-hosted runners, so only the label is off.

[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.

Approved pending CI: CI has not run on this head yet. Its heavy suites were deferred for this push and run in the pre-merge re-run. Measuring a component import no longer writes to the system temp directory and now counts the import's own chunk. Both new tests fail against the old measurement and pass with this change, and on a Core and Charts build only ContextMenuItem, Chart, ChartLegend and ChartTooltip move, each to its own chunk.

  • Optional: the CI impact: line gives deploy.yml's typecheck runner as ubuntu-latest, but that job runs on ubuntu-24.04-arm. Both are standard GitHub-hosted runners, so only the label is off.

[Automated review]

@cixzhang
cixzhang merged commit 47790d3 into main Nov 4, 2026
92 of 95 checks passed
@github-actions
github-actions Bot deleted the ci/component-size-import-chunk branch November 5, 2026 06:03

This branch was successfully deployed

1 active deployment
Preview — c2c02f5b Deployed Nov 4, 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