Skip to content

perf: skip the req/res prototype switch for app.listen() - #7555

Draft
nigrosimone wants to merge 1 commit into
expressjs:masterfrom
nigrosimone:perf/skip-prototype-switch
Draft

nigrosimone wants to merge 1 commit into
expressjs:masterfrom
nigrosimone:perf/skip-prototype-switch

Conversation

@nigrosimone

Copy link
Copy Markdown

app.handle() calls Object.setPrototypeOf on req and res for every request. On Node 24 and 26 this still costs about 2.4 us per request, -22% of app.handle() for a res.send('Hello World!') (in-process bench, numbers per Node version in expressjs/perf-wg#15).

Fix: app.listen() passes to http.createServer an IncomingMessage and ServerResponse with app.request and app.response as prototype, and app.handle() skips the switch when the prototype is already the right one. Mounted apps still switch and restore as before. Apps that call http.createServer(app) themselves keep the switch.

Test: app.listen() serves a request with no switch (fails without the fix with 2 switches), and a mounted app still sees its own prototypes.

@nigrosimone
nigrosimone marked this pull request as ready for review October 24, 2026 06:26
@nigrosimone
nigrosimone marked this pull request as draft October 24, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant