deno/ext/http
Nathan Whitaker 930ccf928a
perf(ext/http): Reduce size of ResponseBytesInner (#24840)
I noticed
[`set_response_body`](ce42f82b5a/ext/http/service.rs (L439-L443))
was unexpectedly hot in profiles, with most of the time being spent in
`memmove`.

It turns out that `ResponseBytesInner` was _massive_ (5624 bytes), so
every time we moved a `ResponseBytesInner` (for instance in
`set_response_body`) we were doing a >5kb memmove, which adds up pretty
quickly.

This PR boxes the two larger variants (the compression streams),
shrinking `ResponseBytesInner` to a reasonable 48 bytes.

---
  Benchmarked with a simple hello world server:
```ts
// hello-server.ts
Deno.serve((_req) => {
  return new Response("Hello world");
});
// run with `deno run -A hello-server.ts`
// in separate terminal `wrk -d 10s http://127.0.0.1:8000`
```

Main:
```
Running 10s test @ http://127.0.0.1:8000/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    53.39us    9.53us   0.98ms   92.78%
    Req/Sec    86.57k     3.56k   91.58k    91.09%
  1739319 requests in 10.10s, 248.81MB read
Requests/sec: 172220.92
Transfer/sec:     24.64MB
```

This PR:
```
Running 10s test @ http://127.0.0.1:8000/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    45.44us    8.49us   0.91ms   90.04%
    Req/Sec   100.65k     2.26k  102.65k    96.53%
  2022296 requests in 10.10s, 289.29MB read
Requests/sec: 200226.20
Transfer/sec:     28.64MB
```

So a nice ~15% bump. (With response body compression, the gain is ~10%
for gzip and neutral for brotli)
2024-08-02 00:30:26 +00:00
..
benches chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
00_serve.ts fix(ext/http): correctly consume response body in Deno.serve (#24811) 2024-08-01 15:46:05 +02:00
01_http.js perf(ext/http): recover memory for serve and optimize AbortController (#23559) 2024-04-25 14:52:24 -04:00
02_websocket.ts fix(ext/websocket): change default idleTimeout to 30s (#23985) 2024-05-26 10:46:05 +05:30
Cargo.toml chore: forward v1.45.5 release commit to main (#24818) 2024-07-31 15:14:27 -07:00
compressible.rs chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
fly_accept_encoding.rs chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
http_next.rs feat(ext/http): Implement request.signal for Deno.serve (#23425) 2024-04-24 14:03:37 -04:00
lib.rs feat(ext/http): Implement request.signal for Deno.serve (#23425) 2024-04-24 14:03:37 -04:00
network_buffered_stream.rs chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
reader_stream.rs chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
README.md chore: add README to ext/http/ (#11958) 2021-09-08 20:48:28 +02:00
request_body.rs chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
request_properties.rs feat(ext/net): Refactor TCP socket listeners for future clustering mode (#23037) 2024-04-08 16:18:14 -06:00
response_body.rs perf(ext/http): Reduce size of ResponseBytesInner (#24840) 2024-08-02 00:30:26 +00:00
service.rs perf(ext/http): Reduce size of ResponseBytesInner (#24840) 2024-08-02 00:30:26 +00:00
websocket_upgrade.rs chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00

deno_http

This crate implements server-side HTTP based on primitives from the Fetch API.