[GH-ISSUE #437] perf: cache startup filesystem scans, optimize base64 and path normalization #94

Closed
opened 2026-05-06 12:37:11 +02:00 by BreizhHardware · 0 comments

Originally created by @Divkix on GitHub (Mar 11, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/437

Problem

Several hot paths in vinext perform redundant work:

  1. hasMdxFiles() recursively walks app/ and pages/ via fs.readdirSync() on every config() hook invocation (fires 3+ times per Vite environment: RSC/SSR/Client)
  2. resolvePostcssStringPlugins() probes 17 PostCSS config file candidates with fs.existsSync() on every config() hook invocation, with no caching
  3. KV cache handler uses byte-by-byte String.fromCharCode/charCodeAt loops for base64 encode/decode instead of Buffer APIs
  4. App Router prod server normalizes the request pathname, then discards it when constructing the Web Request — forcing the RSC handler to re-normalize

Solution

  • Cache hasMdxFiles() and resolvePostcssStringPlugins() results per root directory
  • Replace manual base64 with Buffer.from().toString("base64") / Buffer.from(str, "base64")
  • Pass pre-normalized URL to nodeToWebRequest() so the RSC handler hits the fast path

PR

#436

Originally created by @Divkix on GitHub (Mar 11, 2026). Original GitHub issue: https://github.com/cloudflare/vinext/issues/437 ## Problem Several hot paths in vinext perform redundant work: 1. **`hasMdxFiles()`** recursively walks `app/` and `pages/` via `fs.readdirSync()` on every `config()` hook invocation (fires 3+ times per Vite environment: RSC/SSR/Client) 2. **`resolvePostcssStringPlugins()`** probes 17 PostCSS config file candidates with `fs.existsSync()` on every `config()` hook invocation, with no caching 3. **KV cache handler** uses byte-by-byte `String.fromCharCode`/`charCodeAt` loops for base64 encode/decode instead of `Buffer` APIs 4. **App Router prod server** normalizes the request pathname, then discards it when constructing the Web Request — forcing the RSC handler to re-normalize ## Solution - Cache `hasMdxFiles()` and `resolvePostcssStringPlugins()` results per root directory - Replace manual base64 with `Buffer.from().toString("base64")` / `Buffer.from(str, "base64")` - Pass pre-normalized URL to `nodeToWebRequest()` so the RSC handler hits the fast path ## PR #436
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#94
No description provided.