Skip to content

Commit

Permalink
Generate middlewareManifestPath only once (#55489)
Browse files Browse the repository at this point in the history
Ensures the `join()` is skipped for each request. Did a load test and this increases throughput by about ~150RPS at minimum.
  • Loading branch information
timneutkens authored Sep 17, 2023
1 parent 0bfd480 commit 75ba27c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>
Expand Down Expand Up @@ -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<void> {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 75ba27c

Please sign in to comment.