Skip to content

[Performance]: Eliminate redundant string allocations in request hot-path #712

Description

@arsenz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions