Skip to content

perf(plugins): leave the runtime package out of the prepasses - #1029

Merged
owjs3901 merged 3 commits into
mainfrom
perf/prepass-skip-runtime-package
Nov 19, 2026
Merged

owjs3901 merged 3 commits into
mainfrom
perf/prepass-skip-runtime-package

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Before the bundler starts, two passes read and extract source ahead of time: the shared class-slot reservation (webpack, Rsbuild, Vite, Bun) and the Next production prewarm (Turbopack and Next webpack). Both followed every import of @devup-ui/react into the runtime package's own modules (23 files on the benchmark app: index.js re-exporting every component, hooks, stores, stylex.js...). Resolving and extracting them goes through the JS module resolver for each re-export, but extracting them yields no style (checked on all 34 modules of packages/react/dist: no CSS, no stylesheet, no base-style update).

Both passes now skip @devup-ui/react and its subpaths, from the app and from other Devup UI packages (@devup-ui/components still is read and extracted). RUNTIME_PACKAGE / isRuntimePackage live in plugin-utils, and a new test extracts every module of packages/react/src into one sheet and pins that it stays empty, so the assumption is checked.

If an app keeps a runtime import of @devup-ui/react (e.g. useTheme), the bundler's loader still extracts those modules on demand exactly as before; they just are no longer done ahead of time.

Measurements (local, Windows, 4 alternating A/B runs, native engine)

before (main) after
Turbopack next.setup (DEVUP_UI_PROFILE, single-turbo) 46.2 / 39.3 / 41.1 / 41.1 ms 15.4 / 16.5 / 15.2 / 15.4 ms
of which prewarm 32.3 / 25.9 / 26.7 / 28.0 ms, 25 files 2.7 / 3.7 / 2.8 / 2.8 ms, 2 files
webpack next-devup-ui: CPU in Devup frames (--cpu-prof, all compilers) 339 / 362 / 357 / 345 ms 241 / 251 / 234 / 248 ms

Turbopack: about -25 ms on the config step that runs before Turbopack starts (the Devup part of Running next.config went from ~45 ms to ~20 ms over Tailwind's). Webpack: about -105 ms of CPU per build (the reservation and prewarm run once per compiler: server, edge-server, client). The CI benchmark job of this PR shows the full table.

Output

Byte-identical CSS and page JS (md5) for next-devup-ui-single, next-devup-ui-single-turbo, next-devup-ui-turbo and next-devup-ui-collapse.

next-devup-ui (webpack, per-file) has the same CSS bytes but a different class prefix: the webpack reservation seeds file numbers for its inputs in path order, and the runtime package's modules (../../packages/react/dist/...) used to take numbers 0-22 ahead of src/app/page.tsx. Page classes were x-a...x-o in devup-ui-23.css; now a-a...a-o in devup-ui-0.css. Numbers can only get smaller, so per-file names are never longer.

Notes

Test plan

  • New tests, failing without the change: the reservation and the prewarm skip @devup-ui/react (also @devup-ui/react/stylex, also when imported by @devup-ui/components) while still collecting @devup-ui/components
  • New guard: extracting every module of packages/react/src adds nothing to a single sheet
  • bun test packages/plugin-utils packages/next-plugin packages/webpack-plugin: 4543 pass, 0 fail; 100% for runtime-package.ts, reservation-discovery.ts, prewarm.ts
  • eslint, plugin-utils test:types (in its build)

요약

번들러가 시작되기 전에 소스를 미리 읽고 추출하는 패스가 두 개 있습니다. 공유 class-slot 예약(webpack, Rsbuild, Vite, Bun)과 Next 프로덕션 prewarm(Turbopack, Next webpack)입니다. 둘 다 @devup-ui/react의 import를 런타임 패키지 내부 모듈까지 따라갔습니다(벤치마크 앱에서 23개: 모든 컴포넌트를 다시 내보내는 index.js, hooks, stores, stylex.js...). 이들을 resolve하고 추출하면 다시 내보내기마다 JS 모듈 resolver를 거치지만, 추출해도 스타일이 하나도 나오지 않습니다(packages/react/dist의 34개 모듈 전부 확인: CSS 없음, 스타일시트 없음, base style 갱신 없음).

이제 두 패스 모두 @devup-ui/react와 그 하위 경로를 앱에서든 다른 Devup UI 패키지에서든 건너뜁니다(@devup-ui/components는 여전히 읽고 추출). RUNTIME_PACKAGE / isRuntimePackage는 plugin-utils에 두었고, 새 테스트가 packages/react/src의 모든 모듈을 한 시트로 추출해 비어 있음을 고정하므로 이 전제가 검증됩니다.

앱이 @devup-ui/react를 런타임에 import하면(예: useTheme) 번들러 로더가 해당 모듈을 이전과 똑같이 필요할 때 추출합니다. 미리 하지 않을 뿐입니다.

측정 (로컬, Windows, A/B 교대 4회, native 엔진)

이전 (main) 이후
Turbopack next.setup (DEVUP_UI_PROFILE, single-turbo) 46.2 / 39.3 / 41.1 / 41.1 ms 15.4 / 16.5 / 15.2 / 15.4 ms
그중 prewarm 32.3 / 25.9 / 26.7 / 28.0 ms, 25개 파일 2.7 / 3.7 / 2.8 / 2.8 ms, 2개 파일
webpack next-devup-ui: Devup 프레임 CPU (--cpu-prof, 전체 컴파일러) 339 / 362 / 357 / 345 ms 241 / 251 / 234 / 248 ms

Turbopack: Turbopack 시작 전 config 단계 약 -25 ms (Running next.config에서 Tailwind 대비 Devup 몫이 약 45 ms에서 약 20 ms로). Webpack: 빌드당 CPU 약 -105 ms (예약과 prewarm은 컴파일러마다 실행: server, edge-server, client). 전체 표는 이 PR의 CI benchmark job에 나옵니다.

출력

next-devup-ui-single, next-devup-ui-single-turbo, next-devup-ui-turbo, next-devup-ui-collapse의 CSS와 페이지 JS가 바이트 단위로 동일(md5).

next-devup-ui(webpack, per-file)는 CSS 바이트는 같고 클래스 접두사만 다릅니다. webpack 예약은 입력 파일 번호를 경로 순으로 매기는데, 런타임 패키지 모듈(../../packages/react/dist/...)이 src/app/page.tsx보다 앞에서 0-22번을 가져갔습니다. 페이지 클래스가 devup-ui-23.css의 x-a...x-o에서 devup-ui-0.css의 a-a...a-o가 됩니다. 번호는 작아지기만 하므로 per-file 이름이 길어지는 일은 없습니다.

참고

테스트

  • 새 테스트(변경 없이는 실패): 예약과 prewarm이 @devup-ui/react(그리고 @devup-ui/react/stylex, @devup-ui/components가 import하는 경우도)를 건너뛰고 @devup-ui/components는 계속 수집
  • 새 가드: packages/react/src의 모든 모듈을 추출해도 단일 시트에 아무것도 추가되지 않음
  • bun test packages/plugin-utils packages/next-plugin packages/webpack-plugin: 4543 pass, 0 fail; runtime-package.ts, reservation-discovery.ts, prewarm.ts 100%
  • eslint, plugin-utils test:types(빌드에 포함)

🤖 Generated with Claude Code

owjs3901 and others added 2 commits November 19, 2026 01:50
formatJson counted a trailing comma after every array, so an array that
ends its object and fills exactly 80 columns was split over lines while
Prettier keeps it on one. main's refresh wrote such a row
(devup-ui-large-turbo-wasm), and `bun run lint` rejects history.json again.
The comma now counts only when one follows, and history.json is rewritten.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The shared class-slot reservation and the Next production prewarm followed
every import of @devup-ui/react into its own modules (23 on the benchmark
app), read and resolved them, and extracted them before the bundler started,
although extracting them yields no style. Both now skip the runtime package,
from the app and from other Devup UI packages; a test pins that its modules
add nothing to a sheet.

The webpack reservation seeded file numbers for those modules ahead of the
project's own files, so per-file class prefixes now start at `a-` on the
benchmark app instead of `x-`; the styles are the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
packages/next-plugin/src/prewarm.ts 100.00% <100.00%> (ø)
packages/plugin-utils/src/index.ts 100.00% <100.00%> (ø)
packages/plugin-utils/src/reservation-discovery.ts 100.00% <100.00%> (ø)
packages/plugin-utils/src/runtime-package.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@owjs3901
owjs3901 merged commit 3d2ca7e into main Nov 19, 2026
37 checks passed
@owjs3901
owjs3901 deleted the perf/prepass-skip-runtime-package branch November 19, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant