perf(server): Switch cache compression from deflate to Brotli#1410
Conversation
Use Brotli (quality 4) instead of deflate for in-memory cache compression. Brotli q=4 achieves ~38% better compression ratio than deflate while being faster (0.28ms vs 0.62ms per operation), reducing cache memory footprint. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
⚡ Performance Benchmark
Details
History5493da9 perf(server): Reduce Brotli window size to lower per-call memory
f98b14d refactor(server): Extract Brotli quality level into named constant
7abc77e refactor(server): Use BROTLI_MODE_TEXT and remove redundant Buffer allocation
3ba995c perf(server): Switch cache compression from deflate to Brotli
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughReplaced zlib compression (inflate/deflate) with Brotli compression (brotliDecompress/brotliCompress) in the cache utility. Updated the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Deploying repomix with
|
| Latest commit: |
1bdb18c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://188b8d1e.repomix.pages.dev |
| Branch Preview URL: | https://perf-use-brotli-for-cache-co.repomix.pages.dev |
Code Review — PR #1410Overall: Approve — Clean, well-scoped change. Low risk, correct implementation, credible benchmarks. Findings1. Extract Brotli quality level into a named constant (Suggestion) The magic number const BROTLI_QUALITY = 4; // Balanced speed/ratio for in-memory cacheThis makes the tuning choice explicit and easier to find/adjust later. 2. No tests for DetailsThere are no test files for the cache module (
3. Performance assessment (No concerns) DetailsThe benchmark claims (Brotli q=4: 38% smaller, 2x faster than deflate) are consistent with published compression literature. Brotli at lower quality levels avoids the full Huffman pass and benefits from a superior static dictionary. The choice of q=4 over the default q=11 (which would be 23x slower) is correct for a latency-sensitive cache path. One minor note: under high concurrency, Brotli's compressor state at q=4 uses ~4 MB per active context vs. smaller for deflate. For a Cloud Run deployment with moderate traffic this is negligible, but worth knowing if traffic patterns change significantly. 4. Security (No concerns) The cache is write-then-read within the same process — no path for untrusted compressed data to reach 5. Deployment (No concerns) Cache is purely in-memory with 60s TTL. Server restarts clear it. No rolling-deploy compatibility issues since old deflate entries can't survive a restart. The 6. Conventions (All pass) Commit message, PR title, PR body, checklist, and code style all conform to project conventions. 🤖 Generated with Claude Code |
…location Apply gemini-code-assist suggestion: enable text mode for better compression of JSON cache data and pass string directly to brotliCompress. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Follow-up Review — Incremental FindingsThe previous review covered the main points well. Here are additional observations not yet mentioned: 1. PR description says "60s TTL" but actual usage is 600s (10 minutes) (Minor — docs accuracy) DetailsThe 2. Consider tuning DetailsThe default Brotli window size is 22 (4 MB look-back). For typical cached payloads (tens to hundreds of KB of JSON), a smaller window like 19 (512 KB) would be sufficient and reduces per-compression-call memory allocation. Given the stated goal of reducing Cloud Run memory footprint, this is worth considering alongside the quality setting: [zlib.constants.BROTLI_PARAM_LGWIN]: 19,No blocking issues found. The change is correct, well-scoped, and safe to merge. 🤖 Generated with Claude Code |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Addressed the named constant suggestion in f98b14d. 🤖 |
Set BROTLI_PARAM_LGWIN to 19 (512KB) instead of default 22 (4MB). No impact on compression ratio for typical cache payloads, while reducing memory allocation per compression call. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Smaller window size (512KB) degrades compression ratio significantly for large repositories (26% worse at 7.7MB), which are the payloads that benefit most from compression. Revert to default 4MB window. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Code Review — PR #1410 (Third Pass)Overall: Approve — Previous reviews covered the core analysis well, and the owner addressed both actionable suggestions (named constant, LGWIN tuning). This pass focuses on what's new or unaddressed. New Findings1. Final diff state vs commit history discrepancy (Informational) The PR has 4 commits, but 2. DetailsThe constant holds a log₂ exponent (19), not a byte count. The comment clarifies this, but the name Previously Raised — Still Open
No Concerns
🤖 Generated with Claude Code |
Switch the in-memory cache compression algorithm from deflate to Brotli (quality level 4) to reduce memory footprint on Cloud Run.
Benchmark results (308KB input)
Brotli q=4 provides the best balance: better compression than deflate while actually being faster.
Checklist
npm run testnpm run lint