perf(core): precompute cookie store for request handling#111
perf(core): precompute cookie store for request handling#111halvaradop merged 1 commit intomasterfrom
Conversation
📝 WalkthroughWalkthroughRefactored cookie store initialization in the core index file by introducing two pre-initialized cookie store instances (secure and standard) to replace dynamic per-request creation. Expanded RouterConfig.context with new fields including trustedProxyHeaders, trustedOrigins, and logger, while extracting cookie configuration early in the setup process. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 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)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/core/src/index.ts (1)
36-46: Consider documenting the shared-store assumption.The optimization relies on cookie stores being stateless/immutable. Adding a brief comment clarifies this contract for future maintainers and prevents accidental introduction of per-request state into
createCookieStore.📝 Suggested documentation
const cookiePrefix = authConfig?.cookies?.prefix const cookieOverrides = authConfig?.cookies?.overrides ?? {} + // Cookie stores are stateless and safe to share across requests. + // Only the secure flag differs between instances. const secureCookieStore = createCookieStore(true, cookiePrefix, cookieOverrides, logger) const standardCookieStore = createCookieStore(false, cookiePrefix, cookieOverrides, logger)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/index.ts` around lines 36 - 46, Add a short comment above the createCookieStore usage describing the shared-store assumption: state that secureCookieStore and standardCookieStore are intended to be singleton, stateless/immutable stores shared across requests and must not hold per-request or mutable state; reference createCookieStore, secureCookieStore and standardCookieStore so future maintainers know this contract and ensure any changes to createCookieStore preserve that invariant.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/core/src/index.ts`:
- Around line 36-46: Add a short comment above the createCookieStore usage
describing the shared-store assumption: state that secureCookieStore and
standardCookieStore are intended to be singleton, stateless/immutable stores
shared across requests and must not hold per-request or mutable state; reference
createCookieStore, secureCookieStore and standardCookieStore so future
maintainers know this contract and ensure any changes to createCookieStore
preserve that invariant.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Description
This pull request optimizes cookie store creation by precomputing cookie store instances for middleware usage and request handling. Previously, the cookie store was instantiated per request, introducing unnecessary overhead and creating a performance bottleneck under high load.
With this change, cookie stores are initialized ahead of time and reused based on the connection context (HTTP or HTTPS), separating secure and non-secure configurations. This reduces per-request resource consumption, improves throughput, and enhances overall runtime efficiency without altering existing cookie behavior.