bun: declare the endpoints in Bun.serve routes instead of branching on req.url - #1282
Open
nigrosimone wants to merge 1 commit into
Open
bun: declare the endpoints in Bun.serve routes instead of branching on req.url#1282nigrosimone wants to merge 1 commit into
nigrosimone wants to merge 1 commit into
Conversation
nigrosimone
marked this pull request as ready for review
August 23, 2026 06:06
nigrosimone
requested review from
Kaliumhexacyanoferrat and
MDA2AV
as code owners
August 23, 2026 06:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bun.servehas had aroutesoption since 1.2.3 and this entry runs 1.4, but it does not use it:fetchreceives everything and the handler branches onreq.urlwith a chain ofifs. This declares the endpoints inroutesinstead, so the router matches method and path and fills inreq.params.fetchstays 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: falsesince, 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,routes2,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 /baseline11now gets 404 rather than being answered as a GET. Neither validate.sh nor the profile sends it.completeness.routinggoes to true with it.Ref #1283