-
-
Notifications
You must be signed in to change notification settings - Fork 773
perf: process static assets in parallel #3911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: process static assets in parallel #3911
Conversation
|
Someone is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
π WalkthroughWalkthroughReplaced sequential iteration in Changes
Estimated code review effortπ― 3 (Moderate) | β±οΈ ~20 minutes π₯ Pre-merge checks | β 2 | β 1β Failed checks (1 warning)
β Passed checks (2 passed)
βοΈ Tip: You can configure your own custom pre-merge checks in the settings. β¨ Finishing touches
π§ͺ Generate unit tests (beta)
π Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro π Files selected for processing (2)
π§° Additional context usedπ Path-based instructions (4)src/**/*.{ts,js,tsx,jsx}π CodeRabbit inference engine (AGENTS.md)
Files:
src/**/*.{ts,js}π CodeRabbit inference engine (AGENTS.md)
Files:
src/{build,dev,runner,cli}/**/*.{ts,js}π CodeRabbit inference engine (AGENTS.md)
Files:
src/build/**/*.{ts,js}π CodeRabbit inference engine (AGENTS.md)
Files:
π§ Learnings (2)π Common learningsπ Learning: 2025-12-03T19:09:13.905ZApplied to files:
𧬠Code graph analysis (1)src/build/virtual/public-assets.ts (2)
π Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
π Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (1)
src/build/virtual/public-assets.ts
π§° Additional context used
π Path-based instructions (4)
src/**/*.{ts,js,tsx,jsx}
π CodeRabbit inference engine (AGENTS.md)
src/**/*.{ts,js,tsx,jsx}: Usepathefor cross-platform path operations instead of Node.jsnode:path
Use ESM and modern JavaScript
Do not add comments explaining what the line does unless prompted
Files:
src/build/virtual/public-assets.ts
src/{build,dev,runner,cli}/**/*.{ts,js}
π CodeRabbit inference engine (AGENTS.md)
Use
consolafor logging in build/dev code; usenitro.loggerwhen available
Files:
src/build/virtual/public-assets.ts
src/**/*.{ts,js}
π CodeRabbit inference engine (AGENTS.md)
Use
unstoragefor storage abstraction
Files:
src/build/virtual/public-assets.ts
src/build/**/*.{ts,js}
π CodeRabbit inference engine (AGENTS.md)
Virtual modules must be registered in
src/build/virtual.ts
Files:
src/build/virtual/public-assets.ts
𧬠Code graph analysis (1)
src/build/virtual/public-assets.ts (2)
src/utils/parallel.ts (1)
runParallel(1-40)src/runtime/virtual/server-assets.ts (1)
assets(6-6)
π Additional comments (1)
src/build/virtual/public-assets.ts (1)
9-9: Import looks good.The
runParallelimport is correctly structured using ESM syntax and a proper relative path.
commit: |
|
Just realized I forgot to unite 2 awaits in to single await Promise.all as I did in v2 PR |
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
β»οΈ Duplicate comments (1)
src/build/virtual/public-assets.ts (1)
35-77: The error handling concern from the previous review remains valid.The critical issue flagged in the previous review about
runParallelsilently swallowing errors (rather than failing the build on asset processing failures) still applies to this implementation and should be addressed before merging.The parallelization approach and concurrency limit of 25 are appropriate for this use case.
π§Ή Nitpick comments (1)
src/build/virtual/public-assets.ts (1)
76-76: Optional: Concurrency value could be tunable.The hard-coded concurrency of 25 is reasonable for most cases, but consider making it configurable (e.g., via an environment variable or nitro option) to allow tuning based on system resources and asset count.
π Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (1)
src/build/virtual/public-assets.ts
π§° Additional context used
π Path-based instructions (4)
src/**/*.{ts,js,tsx,jsx}
π CodeRabbit inference engine (AGENTS.md)
src/**/*.{ts,js,tsx,jsx}: Usepathefor cross-platform path operations instead of Node.jsnode:path
Use ESM and modern JavaScript
Do not add comments explaining what the line does unless prompted
Files:
src/build/virtual/public-assets.ts
src/{build,dev,runner,cli}/**/*.{ts,js}
π CodeRabbit inference engine (AGENTS.md)
Use
consolafor logging in build/dev code; usenitro.loggerwhen available
Files:
src/build/virtual/public-assets.ts
src/**/*.{ts,js}
π CodeRabbit inference engine (AGENTS.md)
Use
unstoragefor storage abstraction
Files:
src/build/virtual/public-assets.ts
src/build/**/*.{ts,js}
π CodeRabbit inference engine (AGENTS.md)
Virtual modules must be registered in
src/build/virtual.ts
Files:
src/build/virtual/public-assets.ts
π§ Learnings (2)
π Common learnings
Learnt from: CR
Repo: nitrojs/nitro PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-24T11:45:17.435Z
Learning: Applies to src/build/**/*.{ts,js} : Virtual modules must be registered in `src/build/virtual.ts`
π Learning: 2025-12-03T19:09:13.905Z
Learnt from: medz
Repo: nitrojs/nitro PR: 3834
File: src/presets/cloudflare/server-entry.ts:63-63
Timestamp: 2025-12-03T19:09:13.905Z
Learning: In the Nitro Cloudflare preset (src/presets/cloudflare/server-entry.ts), native errors from oxc-parser and Node.js readFile operations should be allowed to bubble up naturally without wrapping, as their native error messages are more user-friendly and provide better diagnostic information.
Applied to files:
src/build/virtual/public-assets.ts
𧬠Code graph analysis (1)
src/build/virtual/public-assets.ts (2)
src/utils/parallel.ts (1)
runParallel(1-40)src/runtime/virtual/server-assets.ts (1)
assets(6-6)
π Additional comments (2)
src/build/virtual/public-assets.ts (2)
9-9: LGTM: Import is correct.The import properly brings in the
runParallelutility using ESM syntax.
44-47: Excellent: Parallel read and stat per asset.The use of
Promise.allto read the file and get stat information concurrently is a good optimization that eliminates sequential I/O waits for each asset.
pi0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thnx π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and canβt be posted inline due to platform limitations.
β οΈ Outside diff range comments (1)
src/utils/parallel.ts (1)
21-24: Critical: Errors are not being collected into the array.The catch block logs the error but never pushes it to the
errorsarray. This means the returnederrorsarray will always be empty, and the caller's error check will never trigger.π Proposed fix
.then(() => cb(route)) .catch((error) => { + errors.push(error); console.error(error); });
π Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (2)
src/build/virtual/public-assets.tssrc/utils/parallel.ts
π§° Additional context used
π Path-based instructions (4)
src/**/*.{ts,js,tsx,jsx}
π CodeRabbit inference engine (AGENTS.md)
src/**/*.{ts,js,tsx,jsx}: Usepathefor cross-platform path operations instead of Node.jsnode:path
Use ESM and modern JavaScript
Do not add comments explaining what the line does unless prompted
Files:
src/utils/parallel.tssrc/build/virtual/public-assets.ts
src/**/*.{ts,js}
π CodeRabbit inference engine (AGENTS.md)
Use
unstoragefor storage abstraction
Files:
src/utils/parallel.tssrc/build/virtual/public-assets.ts
src/{build,dev,runner,cli}/**/*.{ts,js}
π CodeRabbit inference engine (AGENTS.md)
Use
consolafor logging in build/dev code; usenitro.loggerwhen available
Files:
src/build/virtual/public-assets.ts
src/build/**/*.{ts,js}
π CodeRabbit inference engine (AGENTS.md)
Virtual modules must be registered in
src/build/virtual.ts
Files:
src/build/virtual/public-assets.ts
π§ Learnings (2)
π Common learnings
Learnt from: CR
Repo: nitrojs/nitro PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-24T11:45:17.435Z
Learning: Applies to src/build/**/*.{ts,js} : Virtual modules must be registered in `src/build/virtual.ts`
π Learning: 2025-12-03T19:09:13.905Z
Learnt from: medz
Repo: nitrojs/nitro PR: 3834
File: src/presets/cloudflare/server-entry.ts:63-63
Timestamp: 2025-12-03T19:09:13.905Z
Learning: In the Nitro Cloudflare preset (src/presets/cloudflare/server-entry.ts), native errors from oxc-parser and Node.js readFile operations should be allowed to bubble up naturally without wrapping, as their native error messages are more user-friendly and provide better diagnostic information.
Applied to files:
src/build/virtual/public-assets.ts
𧬠Code graph analysis (1)
src/build/virtual/public-assets.ts (2)
src/utils/parallel.ts (1)
runParallel(1-43)src/runtime/virtual/server-assets.ts (1)
assets(6-6)
π Additional comments (3)
src/utils/parallel.ts (1)
5-6: Return structure is correct, pending the error collection fix.The return type and structure are properly set up to propagate errors to callers. Once the
errors.push(error)is added in the catch block, this will work as intended.Also applies to: 41-42
src/build/virtual/public-assets.ts (2)
35-77: Solid parallelization approach.The implementation is well-structured:
- Concurrency of 25 is appropriate for I/O-bound file operations
- Using
Promise.allfor concurrentreadFile/statwithin each task is a good micro-optimization- Each task writes to a unique key in the shared
assetsobject, avoiding race conditionsOnce the error collection bug in
src/utils/parallel.tsis fixed (addingerrors.push(error)in the catch block), this will properly propagate failures.
79-84: Error aggregation is well-designed.Using
Error.causeto preserve the original errors is good practice for debugging. The combined message with newline separation provides clear visibility into multiple failures.
π Linked issue
#3909
β Type of change
Process static assets in parallel
π Description
π Checklist