Skip to content

perf(cli): the theme contrast check works out each setting's parts once per check - #13474

Closed
josephfarina wants to merge 1 commit into
mainfrom
perf/theme-contrast-parts-per-check
Closed

josephfarina wants to merge 1 commit into
mainfrom
perf/theme-contrast-parts-per-check

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

The theme editor's contrast check (contrastProblems) looks up, for each color pair on each side and in each mode, the latest setting for a part, a token or a fill. Every lookup asked partsOf for the parts each setting lands on, and partsOf walks the groups and each member's fill and border parts every time. A setting's parts depend only on the setting and the project, and the check changes neither, so the same lists were worked out again and again within one check.

Now the check keeps each setting's parts in a map for that one check.

In user terms: show, set and the other theme editor commands that check contrast are faster, and every result is unchanged.

Intended invariant

  • Every result is unchanged: the same problems, fix lines, notes, JSON and exit code.
  • The map belongs to one check: it is made when the check starts and dropped when it ends, so a theme changed between two checks is read as it is then.
  • The callers only read the lists (includes, some, find, for … of), so a kept list is never changed.

Change

  • api/theme-edit/_settings.mjs: contrastProblems reads each setting's parts through a per-check map.
  • api/theme-edit/theme-contrast-settings-each-check.test.mjs: in one process, a later fill, a fill for a state, and a fill that reaches every input followed by the same fill kept to one input each change what the next check finds.
  • No record names how the contrast check reads a setting's parts, so no record changes.

Evidence

  • Test time, three to five alternating runs each, main against main with this change, in one container: theme-readers-part-named-color 53.1 → 41.7 test-s (−21.5%), theme-palette 126.2 → 123.2 (−2.4%), theme-part-own-fill-contrast 5.76 → 5.32 (−8%), theme-contrast-problem-listed-change 7.88 → 7.46 (−5%); the whole theme editor test folder 5,103 → 5,005 test-s (−1.9%, lower in each of the three runs).
  • Results unchanged: across the whole theme editor test folder, every check ran both the old way and the new way and compared the two results (deep equality), and checked that the settings were not changed: 10,715 checks, 0 differences.
  • Product/runtime behavior verified unchanged: the theme editor tests pass with this change (560 files, 6,111 tests, CI=1).
  • CI impact: none (no workflow, action or CI script changes).

Scope

Components: cli (experimental theme editor)

  • 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

  • vitest run --project node packages/cli/api/theme-edit (CI=1): 560 files, 6,111 tests pass.
  • vitest run --project node packages/cli/api/theme-edit/theme-contrast-settings-each-check.test.mjs: 2 tests pass (they pass on main too: they guard against a cache that outlives one check).

replay: worse 0 at 65d9fe3
preflight: pass 65d9fe3

…ce per check

`contrastProblems` asked `partsOf` for the parts a setting lands on at every
lookup, for each pair, side and mode, and `partsOf` walks the groups and the
members' fill and border parts each time. A setting's parts depend only on
the setting and the project, which the check does not change, so the check
now keeps them in a map for that one check. The callers only read the lists.

Tests change the theme between checks in one process (a later fill, a fill
for a state, and a fill that reaches every input then the same fill kept to
one input) and show that each check reads the settings and their parts as
they are then.

[skip ci]
@vercel

vercel Bot commented Nov 21, 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 21, 2026 8:28pm UTC

Request Review

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

astracat-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 21, 2026, 8:47 PM UTC

@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. The head commit's message carries [skip ci], so push a commit without it so the required checks run before merge.

The per-check parts map leaves every contrast result unchanged, because partsOf only reads the setting and the project's part data and no caller changes the kept lists. The contrast tests pass on this head, and one contrast-heavy test file runs about 24% faster.

Claims and files checked

Review mode: full; reason: no-earlier-review

Claims:

  • Changeset: the theme editor checks contrast faster: verified (theme-readers-part-named-color 43.0 to 32.8 test-seconds on base against head)
  • Changeset: a setting's parts are worked out once per check, not per pair, side and mode: verified (_settings.mjs:11857-11870 and its eight call sites)
  • Changeset: what the check finds does not change: verified (partsOf is a pure read, _settings.mjs:5210-5256; the contrast tests pass)
  • Description: each lookup re-walked the groups and the members' fill and border parts: verified (_settings.mjs:5217-5223)
  • Description: the map belongs to one check: verified (local map at _settings.mjs:11861; commitTheme's two checks each make their own)
  • Description: callers only read the lists: verified (all eight call sites use includes, some, find or for … of)
  • Description: show, set and the other contrast-checking commands get faster: verified (_edit.mjs:8833; _settings.mjs:17815, :17821)
  • Description: the new tests show each check reads the current settings and parts, and pass on main too: verified (they pass on base and head)
  • Description: no record names how the check reads a setting's parts: verified
  • Description: test-time figures and the differential comparison: the timings agree with this review's run; the comparison harness is not in the pull request and was not reproduced
  • Description: the whole theme editor test folder passes (560 files): not reproduced in full; the folder holds 561 test files at this head, so that run predates the new test file
  • Description: no public API, product behavior, CI or workflow change: verified

Files:

  • .changeset/theme-contrast-parts-once.md: clear
  • packages/cli/api/theme-edit/_settings.mjs: clear
  • packages/cli/api/theme-edit/theme-contrast-settings-each-check.test.mjs: clear

Automated review (maintainer link)

@josephfarina
josephfarina marked this pull request as ready for review November 21, 2026 21:41
josephfarina added a commit that referenced this pull request Nov 21, 2026
josephfarina added a commit that referenced this pull request Nov 22, 2026
- #13409 experimental theme editor how: "zebra rows taller" is the rows' size, with no stripe (#12971 on main)
  Author: @josephfarina
- #13474 perf(cli): the theme contrast check works out each setting's parts once per check
  Author: @josephfarina
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed in #13489.

@github-actions
github-actions Bot deleted the perf/theme-contrast-parts-per-check branch November 23, 2026 06:06

This branch was successfully deployed

1 active deployment
Preview — 65d9fe36 Deployed Nov 21, 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