Repository navigation
[experimental] render: a page whose script holds a long run of letters and digits renders in its usual time again - #12533
Conversation
… time again The pattern that finds the script's carried(sha256, prefix) calls could start a match at every character of a run of name characters, so a page with a 1 MB string took minutes. It now starts only where a name starts.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
Changes requested. The fix itself is sound: the carried-image pass now reads each run of letters and digits once and rewrites the same calls. Two small fixes remain:
- The new test calls
performance.now()without importing it, so the requiredlintcheck fails withno-undefatpackages/cli/foundation/render/render.test.mjs:263and:265, and the Testing section's ESLint claim does not hold; addimport {performance} from 'node:perf_hooks';as other CLI tests do. - The title says a page with any long string was slow, but only a long run of letters and digits was (a 1 MB base64 or prose string already renders quickly on the base), so reword it to match the changeset, for example "render: a page whose script holds a long run of letters and digits renders in its usual time again", and drop "inline images, fonts" from the description's reasons.
Claims and files checked
Review mode: full; reason: no-earlier-review
Claims:
- Changeset: a page whose script holds a long run of letters and digits renders in its usual time again. Verified: the base pattern takes 96 s on 400,000 characters, the head 3 ms.
- Changeset: the pass started a match at every character of such a run. Verified:
render-page.mjs:749; on the base, time quadruples each time the run doubles. - Changeset: a page with a 1 MB string took minutes. Verified at the pattern level: 400,000 characters already take 96 s. Page renders were not rerun.
- Description: a run of n characters took about n² steps. Verified: 0.24 s, 0.96 s and 3.8 s at 20,000, 40,000 and 80,000 characters.
- Description: a match now starts only where a name starts, so each run is read once. Verified:
render-page.mjs:749. - Description: the calls found and rewritten are unchanged. Verified: identical output on every valid call, and the keep-or-rewrite test passes.
- Description: large strings in real pages (data, inline images, fonts) are affected. False for inline images and fonts: base64 takes 75 ms per 1 MB on the base.
- Description: the new test reads a 400,000-character run in under 2 seconds and still rewrites the call after it, and the old pattern takes about a minute. Verified:
render.test.mjs:257-267passes, and the base pattern takes 96 s on that input. - Description: 80,000 characters take 2.3 s before and under 1 ms after, and 1 MB takes 4 ms. Verified in magnitude on a slower machine: 3.8 s, 1.2 ms and 7.9 ms.
- Description: four generated 1 MB pages time out before and render after,
--reverserestores them exactly, and a render takes 1.43 s against 1.40 s. Not rerun; consistent with the pattern's cost. - Description: one defect is restored, with no new public API and no internal context. Verified: no API or command change, and the public text is clean.
- Description: the render suites pass (788 passed, 3 skipped). Not rerun in full:
render.test.mjspasses 20 of 20, and CI cancelled its test jobs on this head because the CI pool was full. - Description: ESLint passes. False:
no-undefatrender.test.mjs:263and:265. - Description: typecheck passes. Verified for the changed source: no error in the render folder, and tests are outside the typecheck project.
- Description: the knowledge check passes. Verified: CI ran it with warnings only.
- Title: a page with a long string renders in its usual time again. Broader than the fix (second finding).
Files:
.changeset/render-carried-call-linear.md: clear.packages/cli/foundation/render/render-page.mjs: clear.packages/cli/foundation/render/render.test.mjs: the lint finding above.
There was a problem hiding this comment.
Approved pending CI: three test-node shards had not finished on this head yet.
Both earlier points are fixed: the test now imports performance from node:perf_hooks, and the title names a long run of letters and digits. The carried-image pass reads each such run once and rewrites the same calls, so a page with a 1 MB run of letters and digits renders in under a second again.
Claims and files checked
Review mode: incremental; reason: none
Changed rules (0): none.
Claims:
- Changeset: a page whose script holds a long run of letters and digits renders in its usual time again. Verified: a page with a 1 MB run renders in 0.65 s, against 0.63 s before the regression.
- Changeset: the image-read pass started a match at every character of such a run. Verified: the base pattern takes 0.24 s, 0.95 s and 3.8 s at 20,000, 40,000 and 80,000 characters.
- Changeset: a page with a 1 MB string took minutes. Verified: 598 s on the base.
- Title: same claim as the first changeset line. Verified as above.
- Description: such pages took minutes or hit the time limit; a 1 MB string took more than 400 s, against under 2 s before. Verified: 598 s on the base, 0.63 s before the regression.
- Description: strings broken up by other characters (prose, base64) were not affected. Verified: 1 MB of base64 takes 42 ms and 1 MB of prose 8 ms with the base pattern.
- Description: a run of n characters took about n² steps. Verified: time quadruples each time the run doubles.
- Description: a match now starts only where a name starts, so each run is read once. Verified: the lookbehind in the pattern; 4,000,000 characters take 29 ms.
- Description: the calls found and rewritten are unchanged. Verified: the same output on the 1 MB page, and on 200,000 generated scripts a difference only where a name follows a digit, which no call in valid script does.
- Description: the new test reads a 400,000-character run in under 2 s and still rewrites the call after it; the earlier pattern takes about a minute. Verified: the test passes, and the base pattern takes 95 s on its input.
- Description: 80,000 characters take 2.3 s before and under 1 ms after, 1 MB takes 4 ms, and the matches are the same. Verified in magnitude: 3.8 s, 0.6 ms and 8 ms.
- Description: four generated 1 MB pages time out before and render after,
--reverserestores each exactly, each file keeps its size, and a render takes 1.43 s against 1.40 s. Not rerun, as the pages are not in the pull request; consistent with a probe page at 598 s on the base and 0.65 s on the head. - Description: one defect is restored, with no new public API, visual change, default or interaction model, and no internal context. Verified.
- Description: the render suites pass. Partly verified: the changed test file passes 20 of 20; CI's last node test shards had not finished.
- Description: ESLint passes. Verified: CI lint passes and the changed files lint clean.
- Description: typecheck passes. Verified: CI typecheck passes on this head.
- Description: the knowledge check passes. Verified: it reports the templates and records aligned.
Files:
.changeset/render-carried-call-linear.md: clear.packages/cli/foundation/render/render-page.mjs: clear.packages/cli/foundation/render/render.test.mjs: clear; the earlier lint finding is fixed.
User impact
A page whose script holds a long run of letters and digits, such as a long hexadecimal or identifier-like string, took minutes to render or ran into the time limit. A page with such a 1 MB string took more than 400 seconds, where it took under 2 seconds before. A string broken up by other characters (prose, base64) was not affected.
Problem and solution fit
carried(sha256, prefix)calls) could start a match at every character of a run of name characters, so a run of n characters took about n² steps.The match now starts only where a name starts, so each run is read once.
Expected behavior and authority
A render finishes in its usual time whatever text the page holds; the result (which calls are found and rewritten) is unchanged.
Smallest restoration
foundation/render/render-page.mjs: the call pattern starts only at the start of a name.Evidence
foundation/render/render.test.mjs: a script with a 400,000-character run of name characters is read in under 2 seconds and the call after it is still rewritten; with the earlier pattern this takes about a minute.On the same kind of script: 80,000 characters take 2.3 s before and under 1 ms after; 1 MB takes 4 ms; the matches are the same.
On four generated pages that each hold a 1 MB run of letters and digits (relative imports, unusual names, a monorepo layout, and a folder outside any project): before the fix, all four were stopped at 120 seconds with no file; after it, all four render (exit 0),
--reverserestores each exactly, and each file is the same size as before the regression. One render takes 1.43 s, against 1.40 s before the regression.Scope
Testing
CI=1(788 passed, 3 skipped).pnpm check:knowledge.