[PR #436] [MERGED] perf: startup and cache micro-optimizations #571

Closed
opened 2026-05-06 13:08:49 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/436
Author: @Divkix
Created: 3/11/2026
Status: Merged
Merged: 3/11/2026
Merged by: @james-elicx

Base: mainHead: perf/startup-and-cache-micro-optimizations


📝 Commits (6)

  • bd1f6c1 perf: cache startup filesystem scans, optimize base64 and path normalization
  • c0b75a5 fix: validate base64 structural length and improve test spy cleanup
  • 7385c3b fix: address bonk review comments — composite mdx cache key, postcss comment order, hoist test import
  • df119fb Merge remote-tracking branch 'origin/main' into perf/startup-and-cache-micro-optimizations
  • 6a8a891 fix: cache Promise in resolvePostcssStringPlugins to prevent concurrent scan race; add POST urlOverride test
  • 8f2ec4a fmt

📊 Changes

6 files changed (+511 additions, -23 deletions)

View changed files

📝 packages/vinext/src/cloudflare/kv-cache-handler.ts (+16 -12)
📝 packages/vinext/src/index.ts (+38 -5)
📝 packages/vinext/src/server/prod-server.ts (+18 -6)
📝 tests/kv-cache-handler.test.ts (+63 -0)
tests/node-to-web-request.test.ts (+114 -0)
tests/startup-cache.test.ts (+262 -0)

📄 Description

Closes #437

Summary

  • Cache hasMdxFiles() result per root directory — avoids redundant recursive filesystem walks when config() fires per Vite environment (RSC/SSR/Client = 3+ times)
  • Cache resolvePostcssStringPlugins() result per project root — skips repeated existsSync checks across 17 PostCSS config file candidates on each config() invocation
  • Replace byte-by-byte base64 encode/decode in KV cache handler with Buffer APIs for significantly faster serialization
  • Pass pre-normalized URL to nodeToWebRequest() in App Router prod server — eliminates redundant normalizePath call in the RSC handler for pathological URLs

Test plan

  • 9 new tests in tests/startup-cache.test.ts — MDX scan caching (5) and PostCSS config caching (4)
  • 3 new edge-case tests in tests/kv-cache-handler.test.ts — 1 MiB buffer, null bytes, all 256 byte values
  • 5 new tests in tests/node-to-web-request.test.tsurlOverride parameter behavior
  • All 33 kv-cache-handler tests pass
  • Typecheck (tsgo --noEmit) clean
  • Lint (oxlint) clean
  • Format (oxfmt --check) clean

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/436 **Author:** [@Divkix](https://github.com/Divkix) **Created:** 3/11/2026 **Status:** ✅ Merged **Merged:** 3/11/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `perf/startup-and-cache-micro-optimizations` --- ### 📝 Commits (6) - [`bd1f6c1`](https://github.com/cloudflare/vinext/commit/bd1f6c1a3263ab848586a0882560899104744b13) perf: cache startup filesystem scans, optimize base64 and path normalization - [`c0b75a5`](https://github.com/cloudflare/vinext/commit/c0b75a5e9917a095f426d3b479a139cfc6949973) fix: validate base64 structural length and improve test spy cleanup - [`7385c3b`](https://github.com/cloudflare/vinext/commit/7385c3bbdb852515959fa49e3268ac2d3a1787a5) fix: address bonk review comments — composite mdx cache key, postcss comment order, hoist test import - [`df119fb`](https://github.com/cloudflare/vinext/commit/df119fb4ce3261eeee92f8cabd3d911cba2eba73) Merge remote-tracking branch 'origin/main' into perf/startup-and-cache-micro-optimizations - [`6a8a891`](https://github.com/cloudflare/vinext/commit/6a8a891ceca505818300abbf138da8177f64f49d) fix: cache Promise in resolvePostcssStringPlugins to prevent concurrent scan race; add POST urlOverride test - [`8f2ec4a`](https://github.com/cloudflare/vinext/commit/8f2ec4ae8419f145faddbdb72e48635fb3709947) fmt ### 📊 Changes **6 files changed** (+511 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/cloudflare/kv-cache-handler.ts` (+16 -12) 📝 `packages/vinext/src/index.ts` (+38 -5) 📝 `packages/vinext/src/server/prod-server.ts` (+18 -6) 📝 `tests/kv-cache-handler.test.ts` (+63 -0) ➕ `tests/node-to-web-request.test.ts` (+114 -0) ➕ `tests/startup-cache.test.ts` (+262 -0) </details> ### 📄 Description Closes #437 ## Summary - **Cache `hasMdxFiles()` result** per root directory — avoids redundant recursive filesystem walks when `config()` fires per Vite environment (RSC/SSR/Client = 3+ times) - **Cache `resolvePostcssStringPlugins()` result** per project root — skips repeated `existsSync` checks across 17 PostCSS config file candidates on each `config()` invocation - **Replace byte-by-byte base64 encode/decode** in KV cache handler with `Buffer` APIs for significantly faster serialization - **Pass pre-normalized URL to `nodeToWebRequest()`** in App Router prod server — eliminates redundant `normalizePath` call in the RSC handler for pathological URLs ## Test plan - [x] 9 new tests in `tests/startup-cache.test.ts` — MDX scan caching (5) and PostCSS config caching (4) - [x] 3 new edge-case tests in `tests/kv-cache-handler.test.ts` — 1 MiB buffer, null bytes, all 256 byte values - [x] 5 new tests in `tests/node-to-web-request.test.ts` — `urlOverride` parameter behavior - [x] All 33 kv-cache-handler tests pass - [x] Typecheck (`tsgo --noEmit`) clean - [x] Lint (`oxlint`) clean - [x] Format (`oxfmt --check`) clean --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:49 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#571
No description provided.