Chore
Describe the chore
Refactor request and response hot-paths in the Edge Runtime to eliminate unnecessary heap allocations and UTF-8 validations. Specifically, this involves:
- Updating
UserWorkerResponse to use static strings for status_text instead of allocating a new String on every response (since hyper status reasons are static).
- Bypassing unconditional
to_str() UTF-8 validation during header parsing before mapping to Deno ByteString.
- Removing redundant
req_uri.to_string() calls in the server abort logging loop.
The goal is to implement zero-copy mechanisms (&'static str and raw bytes) in these areas to bypass the allocator, thereby reducing memory allocator lock contention and CPU overhead under high concurrency.
Additional context
I have put together a PR that addresses these optimizations, which I will link to this issue shortly.
Baseline load testing using k6/specs/simple.ts demonstrates the following performance improvements after applying this zero-copy refactor:
- Throughput: Increased from ~11,134 RPS to ~12,872 RPS (+15.6%)
- Latency: Average request duration dropped from 1.06ms to 915µs
Chore
Describe the chore
Refactor request and response hot-paths in the Edge Runtime to eliminate unnecessary heap allocations and UTF-8 validations. Specifically, this involves:
UserWorkerResponseto use static strings forstatus_textinstead of allocating a newStringon every response (since hyper status reasons are static).to_str()UTF-8 validation during header parsing before mapping to DenoByteString.req_uri.to_string()calls in the server abort logging loop.The goal is to implement zero-copy mechanisms (
&'static strand raw bytes) in these areas to bypass the allocator, thereby reducing memory allocator lock contention and CPU overhead under high concurrency.Additional context
I have put together a PR that addresses these optimizations, which I will link to this issue shortly.
Baseline load testing using
k6/specs/simple.tsdemonstrates the following performance improvements after applying this zero-copy refactor: