Skip to content

perf: cache startup filesystem scans, optimize base64 and path normalization #437

@Divkix

Description

@Divkix

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions