Skip to content

perf: precompress public assets at brotli quality 10 - #5198

Open
danielroe wants to merge 1 commit into
nitrojs:mainfrom
danielroe:perf/precompress-cost
Open

danielroe wants to merge 1 commit into
nitrojs:mainfrom
danielroe:perf/precompress-cost

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

when public asset compression is enabled, brotli at quality 11 costs quite a lot.

here are some cold nitro build runs with 185 kB of /_nuxt output (6 files) and with 2.6 MB of production assets from a larger site (107 files):

no precompression quality 11 quality 10 quality 9
185 kB of assets 264 ms 437 ms 336 ms 270 ms
2.6 MB of assets 272 ms 1737 ms 849 ms 402 ms
brotli bytes, 185 kB 59.9 kB 60.8 kB 64.2 kB
brotli bytes, 2.6 MB 639 kB 650 kB 690 kB

quality 10 keeps about 98% of the saving for a third of the time, so this PR makes it the default and adds brotliQuality for anyone who would rather have the extra percent:

compressPublicAssets: { brotli: true, brotliQuality: 11 }

Note

this PR also includes a bug fix - the brotli options were being passed one level too high (brotliCompress(buffer, params) instead of { params }). this meant that the quality, the text mode and the size hint were all ignored and the encoder used its own defaults. so instead this PR passes them under params.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe danielroe self-assigned this Nov 30, 2026
@danielroe
danielroe requested a review from pi0 as a code owner November 30, 2026 20:05
@vercel

vercel Bot commented Nov 30, 2026

Copy link
Copy Markdown

@danielroe is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Public asset compression now accepts a configurable Brotli quality, defaulting to 10. The documentation describes the setting and its 0–11 range. Unit tests check output with a configured quality and with the default.

Changes: Brotli quality configuration

Layer / File(s) Summary
Brotli quality option and documentation
src/types/config.ts, docs/3.config/4.assets.md, docs/1.docs/50.assets.md
CompressOptions adds optional brotliQuality. The documentation describes its default of 10, range of 0–11, and an example setting it to 11.
Apply and test Brotli quality
src/utils/compress.ts, test/unit/compress-assets.test.ts
The utility resolves compression settings before processing files and applies the configured Brotli quality, defaulting to 10. Tests compare compressed output with Node Brotli output for configured and default quality.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested labels: bug, assets

Merge Risk: Minimal · up to 4a79d

Public asset Brotli compression now defaults to quality 10, which builds faster, and brotliQuality allows quality 11 when needed. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "perf: precompress public assets at brotli quality 10" follows the conventional commits format with a valid type prefix. It states the main change: public assets are precompressed with Brotl…
Description check Passed The description covers the problem (Brotli quality 11 is slow), benchmark tables comparing quality levels, the new default of quality 10, the new brotliQuality option with an example, and the bug fix …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "perf: precompress public assets at brotli quality 10" follows the conventional commits format with a valid type prefix. It states the main change: public assets are precompressed with Brotli at quality 10, which matches the default change in src/utils/compress.ts and the new brotliQuality option.

Full details: Description check

Explanation

The description covers the problem (Brotli quality 11 is slow), benchmark tables comparing quality levels, the new default of quality 10, the new brotliQuality option with an example, and the bug fix where Brotli options were passed at the wrong level. It relates directly to the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0bda38c1-0e08-4529-b9ba-d418ba35854e
Commits

Reviewing files that changed from the base of the PR and between 925c135 and 4a79d54.

Files selected for processing: 5

  • docs/1.docs/50.assets.md
  • docs/3.config/4.assets.md
  • src/types/config.ts
  • src/utils/compress.ts
  • test/unit/compress-assets.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@5198

commit: 4a79d54

This branch has not been deployed

No deployments
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