Skip to content

bun: declare the endpoints in Bun.serve routes instead of branching on req.url - #1282

Open
nigrosimone wants to merge 1 commit into
MDA2AV:mainfrom
nigrosimone:bun-routes
Open

bun: declare the endpoints in Bun.serve routes instead of branching on req.url#1282
nigrosimone wants to merge 1 commit into
MDA2AV:mainfrom
nigrosimone:bun-routes

Conversation

@nigrosimone

@nigrosimone nigrosimone commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Bun.serve has had a routes option since 1.2.3 and this entry runs 1.4, but it does not use it: fetch receives everything and the handler branches on req.url with a chain of ifs. This declares the endpoints in routes instead, so the router matches method and path and fills in req.params. fetch stays as the 404.

I should say where this comes from, because it looks bad otherwise. I wrote that first implementation myself in #1163 on 15 August, when completeness did not exist and not using the router cost nothing. Completeness arrived on 21 August in #1223 and the entry has carried routing: false since, which is an accurate description of my code and takes 2.5% off its composite, about 23 points on the published numbers. So a choice that was free when I made it now costs points to a framework that competes with mine, and I would rather fix it than leave it there to be read as me having favoured my own entry.

It is not a trade. Measured locally on the baseline shape with bun 1.3.14, alternating rounds: the chain of ifs 2,812 req/s, routes 2,832. The router is free here, so the 2.5% is a straight gain.

Every endpoint answers what it answered before, checked request by request against the previous build: the three baseline shapes, json with and without gzip, upload, static with identity and br, the missing file, the traversal guard, async-db, fortunes and the four crud verbs. One difference, on a method nobody sends: DELETE /baseline11 now gets 404 rather than being answered as a GET. Neither validate.sh nor the profile sends it.

completeness.routing goes to true with it.

Ref #1283

@nigrosimone
nigrosimone marked this pull request as ready for review August 23, 2026 06:06
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