From 75ba27c22258cb3e9f5f7b9ffc54ca3e42c78e8b Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 17 Sep 2023 12:25:19 +0200 Subject: [PATCH] Generate middlewareManifestPath only once (#55489) Ensures the `join()` is skipped for each request. Did a load test and this increases throughput by about ~150RPS at minimum. --- packages/next/src/server/next-server.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index f5d3d7feb62eb..0271395ba1d13 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -145,6 +145,7 @@ function getMiddlewareMatcher( } export default class NextNodeServer extends BaseServer { + protected middlewareManifestPath: string private _serverDistDir: string | undefined private imageResponseCache?: ResponseCache protected renderWorkersPromises?: Promise @@ -231,6 +232,8 @@ export default class NextNodeServer extends BaseServer { const { interceptTestApis } = require('../experimental/testmode/server') interceptTestApis() } + + this.middlewareManifestPath = join(this.serverDistDir, MIDDLEWARE_MANIFEST) } protected async handleUpgrade(): Promise { @@ -1335,10 +1338,7 @@ export default class NextNodeServer extends BaseServer { protected getMiddlewareManifest(): MiddlewareManifest | null { if (this.minimalMode) return null - const manifest: MiddlewareManifest = require(join( - this.serverDistDir, - MIDDLEWARE_MANIFEST - )) + const manifest: MiddlewareManifest = require(this.middlewareManifestPath) return manifest }