Skip to content

perf(router): avoid Promise allocation in synchronous dispatch path#332

Closed
cesco69 wants to merge 2 commits intodimdenGD:mainfrom
cesco69:perf-route
Closed

perf(router): avoid Promise allocation in synchronous dispatch path#332
cesco69 wants to merge 2 commits intodimdenGD:mainfrom
cesco69:perf-route

Conversation

@cesco69
Copy link
Copy Markdown
Contributor

@cesco69 cesco69 commented Apr 14, 2026

Add sync-first dispatch via _syncDispatch/_syncNext that skips new Promise() when route callbacks are synchronous.
Falls back to _routeRequestAsync only for Router instances or async callbacks.

Eg:

app.use(cors());        // sync -> no Promise allocated
app.use(helmet());      // sync -> no Promise allocated

app.get('/data', async (req, res) => {
  const rows = await db.query('SELECT 1');
  res.json(rows);
});
// ^ async -> falls back to Promise only from here

@cesco69 cesco69 closed this Apr 14, 2026
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