Repository navigation
perf: speed up middleware routes and whole-body uploads - #21
Conversation
Routes behind middleware without a body reader now take the lazy fast path, and a plain 200 with one folded block of default headers goes out with one head write. bytes() collects the body inside the reader instead of through an async generator, the exchange calls the body reader directly instead of through listeners, and the framing scan allocates less.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Speed checkh2load sent Does this PR make uhttp slower?The job never fails on this table.
uhttp is 0.5% slower after this PR than before it, which is less than the 3.2% that the job treats as machine noise, so this PR leaves the speed of uhttp unchanged. How much slower is uhttp than uWebSockets.js?The job fails when uhttp after this PR is more than 5.0% slower in the median round.
After this PR, uhttp is 2.1% slower than uWebSockets.js, and before this PR, it was 2.3% slower. The job passes, because the limit is 5.0% slower. |
Summary
secureHeaders(), goes out in one head write.bytes()collects the body inside the body reader instead of through an async generator. The exchange calls the reader directly instead of through listeners.isDecimalDigitschecks character codes in a loop instead of matching a regular expression.bytes()call with the matching error.Testing
bytes().REQUEST_ABORTED, and the next client is served.maxBodyBytesgets a 413, the connection closes, and the handler never runs.request-context.test.tsnow run with no middleware, with synchronous middleware, and with asynchronous middleware.pnpm nx run uhttp:speedran three times on a quiet machine. Results: 3.6% faster, 0.9% slower, and 1.6% slower than uWebSockets.js, all within the 5% limit.