Skip to content

perf: optimize body parsing and buffering in request handling with onDataV2#335

Open
nigrosimone wants to merge 1 commit intodimdenGD:mainfrom
nigrosimone:perf-ondata-v2
Open

perf: optimize body parsing and buffering in request handling with onDataV2#335
nigrosimone wants to merge 1 commit intodimdenGD:mainfrom
nigrosimone:perf-ondata-v2

Conversation

@nigrosimone
Copy link
Copy Markdown
Contributor

@nigrosimone nigrosimone commented Apr 18, 2026

Switches from onData to onDataV2 which exposes maxRemainingBodyLength the exact number of bytes remaining in the request body. This enables several performance optimizations like pre-allocated body buffer.

PR BENCHMARK

Test Express req/sec uExpress req/sec Express throughput uExpress throughput uExpress speedup
engines/art 4.32k 10.19k 1.89 MB/sec 4.48 MB/sec 2.37x
middlewares/body-urlencoded 7.15k 33.86k 1.11 MB/sec 5.30 MB/sec 4.77x
middlewares/compression-file 4.76k 6.97k 2.17 MB/sec 3.18 MB/sec 1.47x
middlewares/express-static 2.42k 6.89k 592.86 MB/sec 1.64 GB/sec 2.83x
routing/hello-world 11.07k 70.89k 1.84 MB/sec 11.83 MB/sec 6.43x
routing/middlewares-100 10.14k 14.65k 1.59 MB/sec 2.31 MB/sec 1.45x
routing/nested-routers 10.18k 59.03k 1.63 MB/sec 9.51 MB/sec 5.83x
routing/routes-1000 3.27k 54.06k 523.02 KB/sec 8.51 MB/sec 16.66x
streaming/readable-hash-4mb 10.82k 69.21k 4.00 MB/sec 25.67 MB/sec 6.42x
streaming/writable-no-content-length 500.09 533.87 2.44 GB/sec 2.62 GB/sec 1.07x
streaming/writable-with-content-length 513.71 417.06 2.51 GB/sec 2.05 GB/sec 0.82x

MASTER BENCHMARK

Test Express req/sec uExpress req/sec Express throughput uExpress throughput uExpress speedup
engines/art 4.06k 7.86k 1.78 MB/sec 3.46 MB/sec 1.94x
middlewares/body-urlencoded 5.84k 18.26k 931.84 KB/sec 2.86 MB/sec 3.14x
middlewares/compression-file 3.26k 6.72k 1.49 MB/sec 3.07 MB/sec 2.06x
middlewares/express-static 2.01k 7.19k 492.15 MB/sec 1.72 GB/sec 3.58x
routing/hello-world 7.74k 52.99k 1.28 MB/sec 8.84 MB/sec 6.91x
routing/middlewares-100 7.54k 12.55k 1.18 MB/sec 1.97 MB/sec 1.67x
routing/nested-routers 7.29k 42.18k 1.17 MB/sec 6.80 MB/sec 5.81x
routing/routes-1000 3.41k 38.51k 545.72 KB/sec 6.06 MB/sec 11.37x
streaming/readable-hash-4mb 7.87k 53.41k 2.91 MB/sec 19.82 MB/sec 6.81x
streaming/writable-no-content-length 542.93 581.82 2.66 GB/sec 2.85 GB/sec 1.07x
streaming/writable-with-content-length 560.60 627.22 2.74 GB/sec 3.07 GB/sec 1.12x

@nigrosimone nigrosimone marked this pull request as ready for review April 18, 2026 18:31
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