Skip to content

chore(scripts): one measurer for INV10's reference pages (pnpm size:pages) - #11731

Merged
cixzhang merged 7 commits into
mainfrom
tools/measure-reference-pages
Nov 15, 2026
Merged

cixzhang merged 7 commits into
mainfrom
tools/measure-reference-pages

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

architecture:component-import-boundaries INV10 asks a pull request to report first-load gzip deltas on four reference pages (docs, form, menu, table). Until now each author or reviewer built their own measurer. The numbers then disagree by build method: whether Core is compiled as published, whether its sideEffects applies, the gzip level, and which packages stay external. A pull request near INV10's 0.3 KB limit can pass with one measurer and fail with another.

Intended invariant

  • INV10: an unused optional feature adds at most 0.3 KB gzip of first-load JavaScript to a page that renders its component without it. A pull request that grows a shared module reports the per-page delta on the four reference pages, each "a production app bundle of the built packages that imports exactly these Core components".
  • The size report and the import-boundaries check measure an import through .github/scripts/lib/component-size.js. This script uses the same helper: its esbuild options, its externals (React, React DOM and StyleX, as the boundaries check) and its extraction of a ref's source. Totals still differ by design: the boundaries check bundles Core's raw source, this script bundles Babel output as published (INV10's "built packages"), and the size report also bundles React. So compare deltas from one tool, not totals across tools.

Change

pnpm size:pages (scripts/measure-reference-pages.mjs):

  • Pages from the record. It reads the four reference pages and their component lists from INV10's own sentence, so the measured pages cannot drift from the record. --page name=A,B adds a page, for a shared module none of the four reaches, as INV10 allows.
  • Built packages. For each side (a git ref, the working tree, or a built dist directory such as Core's own dist/), it compiles Core's src with that ref's Babel config and build:esm's ignore list (read from that ref's package.json), so StyleX compiles as published. Both sides build (or, for a dist directory, are copied with their package.json) under the same relative layout, so unchanged code bundles to the same bytes. It copies Core's package.json into the dist, so sideEffects applies as it does for an app. Any Babel error stops the run, because a partial build gives plausible but wrong sizes. Generated source that git does not track comes from the working tree, as in the import-boundaries check.
  • Measurement. It bundles each page with sizeBuildOptions and eagerText/gzipBytes from the shared helper, with React, React DOM and StyleX external as in the boundaries check. It prints first-load minified and gzip bytes, base and head, and the delta per page.
  • Verdicts. --unused-on <page,…> prints PASS or FAIL per named page against the 0.3 KB limit (307 B, KB = 1024 B, as the boundaries check prints KB) and exits 1 on a failure. --json prints the same as JSON.
  • Shared helpers. Extracting a ref's source (extractAtRef) and the app externals (APP_EXTERNALS) move from the boundaries check into component-size.js, and both scripts call them, so the two measurers cannot drift apart. The boundaries check's output is unchanged.
  • No CI job: people and review agents run it.
  • Record: INV10's verification row names pnpm size:pages as the source of the per-page report, and INV10 states its unit: "0.3 KB gzip (KB as the boundary check prints it, 1,024 bytes)".

Evidence

  • Failure before the change: no shared measurer. On one pull request, two hand-built measurers differed by about 5 KB gzip per page, because one did not apply Core's sideEffects.
  • Success after the change:
    • Same Core on both sides: 0 B on all four pages, for the same ref twice, a ref against the working tree, and Core's own dist/ on both sides. Core's built dist/ and a fresh build of the same commit print the same sizes.
    • A recent Selector change that grew Typeahead and Tokenizer, measured with --page typeahead=Typeahead --page tokenizer=Tokenizer: Typeahead +902 / +343 B, Tokenizer +927 / +303 B, the four reference pages 0 to +3 B.
    • A pending DropdownMenu sub-menu change: table +901 / +327 B (FAIL at 307 B), menu +522 / +253 B (PASS), docs and form 0. An independent esbuild-over-Babel build gave the same minified deltas, with gzip within 4 B.
  • Product/runtime behavior verified unchanged: no package source changes.
  • CI impact: none; no workflow changes.

Scope

Components: none (repository script and its test; package.json script entry; the shared size helper and the boundaries check's use of it; the INV10 record's verification row and unit clause)

  • No intended public API, product behavior, visual direction, or policy change. (The record clause states the unit the boundary check already prints.)
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Writing rubric results

Record changed: architecture:component-import-boundaries. INV10 gains one clause stating its unit ("KB as the boundary check prints it, 1,024 bytes"). The INV10 verification row's evidence now names pnpm size:pages as the report's source.

  • R1 narration: none; present tense.
  • R2 research: none.
  • R3 evidence: names the script that produces the evidence, which this PR adds.
  • R4 rejected alternatives: none.
  • R5 change references: none.
  • R6 open questions: none.

Testing

  • vitest run --project node scripts/measure-reference-pages.test.mjs: 9 tests. They cover the parser against the real record and a synthetic one, the missing-INV10 and no-page errors, the delta math, the 307 B boundary (pass at 307, fail at 308), the report line, and argument parsing.
  • pnpm size:pages --base HEAD --head . (identical Core): 0 B on every page.
  • vitest run --project node scripts/check-component-import-boundaries.test.mjs .github/scripts/lib/component-size.test.mjs: pass; pnpm check:component-import-boundaries --base-ref HEAD: unchanged output, boundaries hold.
  • check:portable-scripts, Prettier, ESLint: pass.

@vercel

vercel Bot commented Nov 14, 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 15, 2026 3:02am UTC

Request Review

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

astracat-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

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

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 433878b

Storybook · Sandbox · built from this PR's head

Package size: no published package changed; no new dependencies.

Not run on this PR: add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.

CI impact: 0 job-min per update · pool 0% · time to green −3.2 min · standard runners · 1 CI action or script file changed (not measured)
Before After Change
Job-minutes per PR update 173.3 173.3 0
Runner pool, runner-minutes a day 69,333 69,333 0 (0%)
Average concurrent jobs 48.1 48.1 0
Time to green (median → this run) 22.3 min 19.1 min −3.2 min
Runs a day 400 400 0

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

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

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 14, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 600e4c5

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 14, 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.

Changes requested. pnpm size:pages gives INV10's reference pages one shared measurer, and its page list, Babel build and 307 B limit check out. Three things need fixing first:

  • Gzip deltas depend on the build directory name, not only the code. With identical Core on both sides (--base <ref> against the working tree), the per-page gzip delta ranged from −7 to +4 B, because esbuild's chunk names hash the dist-<ref> and dist-working-tree paths (scripts/measure-reference-pages.mjs:197-199). Building both sides under the same relative layout should make unchanged code read 0 B.
  • exportSource and the external list copy extractBaseSource and buildOptions from scripts/check-component-import-boundaries.mjs line for line. Move them into .github/scripts/lib/component-size.js and call them from both scripts, so the two measurers cannot drift apart.
  • The description's "all three print comparable numbers" is not true. On this head, the boundaries check prints eager gzip of 12.4 KB for Text, 61.2 KB for Button and 134.2 KB for Table, while size:pages prints 10.3 KB, 59.8 KB and 133.5 KB (raw source against Babel output, and the size report bundles React), so please reword it.

Two smaller notes: a ref side compiles with the working tree's Babel config, and a --base/--head dist must hold package.json beside <Name>/index.js, which Core's own dist/ does not.

Claims and files checked
  • Pages come from INV10's own sentence, and --page adds one: verified (real-record test; parser at lines 43-62).
  • Core compiles with its Babel config and the build:esm ignore list, and package.json is copied so sideEffects applies: verified (lines 193-234). A ref side uses the working tree's Babel config (note above).
  • Any Babel error stops the run: verified (lines 223-228).
  • Untracked generated source comes from the working tree, as in the boundaries check: verified (lines 153-175, the same logic as that check).
  • Pages are bundled with sizeBuildOptions, eagerText and gzipBytes, with React, React DOM and StyleX external: verified (lines 248-295).
  • PASS or FAIL against 307 B (KB of 1,024 bytes), exit 1 on a failure, and --json: verified (lines 37, 88 and 355, and the tests).
  • No CI job: verified (no workflow change).
  • INV10 gains the unit clause, and its verification row names pnpm size:pages: verified.
  • All three tools print comparable numbers: false (see above).
  • The same commit on both sides gives 0 B: true only with the same ref on both sides. A ref against the working tree gives −7 to +4 B.
  • The Selector and DropdownMenu measurements and the 5 KB measurer disagreement: not reproduced (no refs given).
  • 9 tests pass, and Prettier and ESLint pass: verified on this head.
  • Files: scripts/measure-reference-pages.mjs (three blocking findings, two notes); scripts/measure-reference-pages.test.mjs, package.json and docs/architecture/component-import-boundaries.md (clear).

Automated review (maintainer link)

Comment thread scripts/measure-reference-pages.mjs Resolved
Comment thread scripts/measure-reference-pages.mjs Resolved
Comment thread scripts/measure-reference-pages.mjs Resolved
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec f2dbe49

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

Changes requested. pnpm size:pages gives INV10's reference pages one shared measurer, and unchanged Core reads 0 B when both sides are refs or the working tree. One thing remains:

  • A built-dist side such as --base packages/core/dist is bundled from its own parent instead of the shared <side>/dist layout (scripts/measure-reference-pages.mjs:176-186), so identical Core reads +1 B gzip on the menu and table pages, against the description's and buildCore's "unchanged code bundles to the same bytes"; copy the dist into <side>/dist with its package.json beside it, or narrow both sentences to ref and working-tree sides.

A non-blocking suggestion sits inline on measurePage.

Claims and files checked
  • Pages come from INV10's sentence, and --page adds one: verified (lines 45-64 and the real-record test).
  • Each side compiles Core with that ref's Babel config and build:esm ignore list: verified for ref and working-tree sides (lines 131-165, 199-215).
  • Both sides build under the same layout, so unchanged code bundles to the same bytes: true for refs and the working tree (0 B measured); false for a built dist directory (finding above).
  • package.json sits beside the output so sideEffects applies: verified (lines 223-226); a dist side uses the one above it.
  • Any Babel error stops the run: verified (lines 217-222).
  • Untracked generated source comes from the working tree: verified (extractAtRef).
  • Pages bundle with the shared esbuild options, eager-chunk walk and gzip, with React, React DOM and StyleX external: verified (lines 242-283).
  • PASS or FAIL against 307 B, exit 1 on a failure, and --json: verified (lines 39, 70-94, 349 and the tests).
  • extractAtRef and APP_EXTERNALS are shared, and the import-boundaries check's output is unchanged: verified (identical output before and after).
  • Totals differ by tool by design, so compare deltas from one tool: verified.
  • No CI job: verified (no workflow change).
  • INV10 states its unit, and its verification row names pnpm size:pages: verified.
  • Same Core on both sides gives 0 B, for one ref twice and for a ref against the working tree: verified.
  • The Selector and DropdownMenu measurements and the earlier 5 KB disagreement: not reproduced (no refs given).
  • The 9 new tests, the boundaries and size-helper suites, and Prettier pass: verified; ESLint exits 0, but the ESLint config ignores scripts/** and .github/scripts/**.
  • No package source changes: verified.
  • Files: scripts/measure-reference-pages.mjs (finding above, plus a non-blocking note); .github/scripts/lib/component-size.js, scripts/check-component-import-boundaries.mjs, scripts/measure-reference-pages.test.mjs, package.json and docs/architecture/component-import-boundaries.md (clear).

Automated review (maintainer link)

Comment thread scripts/measure-reference-pages.mjs Resolved
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec d54c9c2

@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: every job skips while the pull request is a draft, so marking it ready for review runs it.

pnpm size:pages now reads 0 B on identical Core for ref, working-tree and built-dist/ sides alike, and both record edits carry an engineering owner's approval for this head. No blocking findings remain; one non-blocking suggestion sits inline on measurePage.

Claims and files checked
  • Pages are read from INV10's sentence and --page adds one: verified (parser at lines 45-64, the real-record test, an extra-page run).
  • Each side compiles Core with that ref's Babel config and build:esm ignore list: verified (lines 131-165, 202-218).
  • Every side, a built dist/ included, sits in one layout, so unchanged code bundles to the same bytes: verified (lines 179-191; 0 B on every page for every pairing).
  • package.json sits beside the output so sideEffects applies: verified (lines 189-190, 226-229).
  • Any Babel error stops the run: verified (lines 220-225).
  • Untracked generated source comes from the working tree: verified (extractAtRef).
  • Pages bundle with the shared esbuild options, eager-chunk walk and gzip, with React, React DOM and StyleX external: verified (lines 245-286).
  • PASS or FAIL against 307 B with exit 1 on a failure, and --json: verified (lines 39, 70-94, 352 and the tests).
  • extractAtRef and APP_EXTERNALS are shared, and the import-boundaries check's output is unchanged: verified (same output before and after, apart from its elapsed time).
  • Totals differ by tool by design, so compare deltas from one tool: verified.
  • No CI job and no workflow change: verified.
  • INV10 states its unit, and its verification row names pnpm size:pages: verified.
  • Identical Core reads 0 B for one ref twice, a ref against the working tree, and dist/ on either or both sides: verified.
  • The Selector, DropdownMenu, independent-build and earlier 5 KB measurements: not reproducible here (no refs given).
  • The 9 new tests, the boundaries and size-helper suites, the portable-scripts check and Prettier pass: verified; ESLint exits 0, but its config ignores scripts/** and .github/scripts/**.
  • No package source or product behaviour changes: verified.
  • Files: scripts/measure-reference-pages.mjs (non-blocking note); .github/scripts/lib/component-size.js, scripts/check-component-import-boundaries.mjs, scripts/measure-reference-pages.test.mjs, package.json and docs/architecture/component-import-boundaries.md (clear).

Automated review (maintainer link)

const ENTRY_SOURCE = '__astryx-reference-page__.mjs';

/** One page as a production app bundle: what it loads before first paint. */
export async function measurePage(distDir, components) {

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.

Non-blocking: this repeats measureEntry's stdin build, entry-output lookup, textByPath map and eagerText/gzipBytes step in scripts/check-component-import-boundaries.mjs (lines 383-447). The options, externals and eager-chunk walk are already shared, so the two agree today; a build-and-measure helper in .github/scripts/lib/component-size.js that takes a list of exports would keep that glue in one place too.

…ce-pages

# Conflicts:
#	docs/architecture/component-import-boundaries.md
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 14, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 11a3fec

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

Changes requested. pnpm size:pages reads 0 B on identical Core and both record edits carry an engineering owner's approval for this head, but the merge of main broke the import-boundaries check.

  • Regression: removing import {execFileSync} from 'node:child_process' from scripts/check-component-import-boundaries.mjs now leaves the base-record read that main added (line 1056) unbound, so every --base-ref run, the Lint workflow's included, prints "Must-not-reach base skipped" and never lists a "Must not reach" row a pull request removes, which INV9 requires; keeping the import fixes it.

The inline comment on that import line explains the reproduction, and the non-blocking suggestion on measurePage stays open inline. CI has not run on this draft head.

Claims and files checked

Review mode: same-head; reason: none

  • Pages are read from INV10's sentence and --page adds one: verified (parseReferencePages, lines 45-64, and the real-record test).
  • Each side compiles Core with that ref's Babel config and build:esm ignore list: verified (lines 131-165, 202-218).
  • Every side sits in one layout, so unchanged code bundles to the same bytes: verified (lines 176-192; the base commit against the working tree reads +0 / +0 on all four pages).
  • package.json sits beside the output so sideEffects applies: verified (lines 190, 226-229).
  • Any Babel error stops the run: verified (lines 219-225).
  • Untracked generated source comes from the working tree: verified (extractAtRef in the shared helper; the working-tree side copies its own src).
  • Pages bundle with the shared esbuild options, eager-chunk walk and gzip, with React, React DOM and StyleX external: verified (lines 245-286).
  • PASS or FAIL against 307 B with exit 1 on a failure, and --json: verified (lines 39, 70-94, 352 and the tests).
  • extractAtRef and APP_EXTERNALS are shared by both scripts: verified.
  • The boundaries check's output is unchanged, including with --base-ref: false at this head (it now prints a skip line and drops the removed-row report; see the finding above).
  • Totals differ by tool by design, so compare deltas from one tool: verified.
  • No CI job and no workflow change: verified.
  • INV10 states its unit, and its verification row names pnpm size:pages: verified.
  • Identical Core reads 0 B: verified for a ref against the working tree at this head; the built-dist/ path is unchanged since it was verified.
  • The Selector, DropdownMenu, independent-build and earlier 5 KB measurements: not reproducible here (no refs given).
  • The 9 new tests and the boundaries and size-helper suites pass: verified (55 of 55); Prettier is clean; ESLint ignores scripts/** and .github/scripts/**.
  • No package source or product behaviour changes: verified.
  • Files: scripts/check-component-import-boundaries.mjs (blocking); scripts/measure-reference-pages.mjs (non-blocking note); .github/scripts/lib/component-size.js, scripts/measure-reference-pages.test.mjs, package.json and docs/architecture/component-import-boundaries.md (clear).

Automated review (maintainer link)

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 15, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec a7912b1

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 15, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 433878b

@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: every job skips while the pull request is a draft, so marking it ready for review runs it. pnpm size:pages reads +0 / +0 on identical Core for ref, working-tree and built dist/ sides, the import-boundaries check again prints the same report as on the base (removed "Must not reach" rows included), and both record edits carry an engineering owner's approval for this head.

One non-blocking suggestion stays open inline: measurePage could share the boundaries check's build-and-measure glue through the size helper.

Claims and files checked

Review mode: full; reason: merge-touches-pr-files

  • The pages are read from INV10's sentence, and --page adds one: verified (parseReferencePages, lines 45-64, and the real-record test).
  • Each side compiles Core with that ref's Babel config and build:esm ignore list: verified (lines 131-165, 202-218; the arguments match Core's build:esm).
  • Every side sits in one layout, so unchanged code bundles to the same bytes: verified (lines 176-192; +0 / +0 for ref, working-tree and dist/ sides).
  • Core's package.json sits beside the output so sideEffects applies: verified (lines 190, 226-229; Core's globs all start with **/).
  • Any Babel error stops the run: verified (lines 219-225).
  • Untracked generated source comes from the working tree: verified (extractAtRef in the shared helper).
  • Pages bundle with the shared esbuild options, eager-chunk walk and gzip, with React, React DOM and StyleX external: verified (lines 245-286).
  • The report prints minified and gzip bytes, base, head and delta: verified (formatComparison and the runs).
  • PASS or FAIL against 307 B (1 KB = 1,024 B, as the boundaries check prints KB), exit 1 on a failure, and --json: verified (lines 39, 70-94, 352 and the tests).
  • extractAtRef and APP_EXTERNALS are shared by both scripts: verified.
  • The boundaries check's output is unchanged: verified (identical to the base revision of the check, with and without a removed "Must not reach" row).
  • Totals differ by tool by design, so compare deltas from one tool: verified.
  • No CI job and no workflow change: verified.
  • INV10 states its unit, and its verification row names pnpm size:pages: verified.
  • Identical Core reads 0 B, and Core's built dist/ matches a fresh build of the same commit: verified.
  • The Selector, DropdownMenu, independent-build and earlier 5 KB measurements: not reproducible here (no refs given).
  • The 9 new tests and the boundaries and size-helper suites pass: verified (55 of 55); Prettier is clean; the portable-scripts rule finds no offence in the root scripts; ESLint ignores scripts/** and .github/scripts/**.
  • No package source or product behaviour changes: verified.
  • Files: scripts/measure-reference-pages.mjs (non-blocking note); scripts/measure-reference-pages.test.mjs, .github/scripts/lib/component-size.js, scripts/check-component-import-boundaries.mjs, package.json and docs/architecture/component-import-boundaries.md (clear).

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as ready for review November 15, 2026 06:06
@cixzhang
cixzhang merged commit ccf2a64 into main Nov 15, 2026
150 checks passed
@github-actions
github-actions Bot deleted the tools/measure-reference-pages branch November 16, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — 433878b6 Deployed Nov 15, 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