perf(runtime): eliminate hot-path string allocations#710
Open
arsenz wants to merge 1 commit into
Open
Conversation
- Replaced `String` with `&'static str` for `status_text` in `UserWorkerResponse`. - Bypassed UTF-8 validation overhead by mapping raw bytes to Deno `ByteString` for headers. - Removed `req_uri.to_string()` allocation during abort logging in the server loop. This optimization yielded a ~15.6% increase in throughput (RPS) and achieved sub-millisecond average latency during baseline k6 benchmarking.
This was referenced Jun 22, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Performance optimization (
perf)What is the current behavior?
Currently, the Edge Runtime performs unnecessary heap allocations and UTF-8 validations on every incoming request in the hot-path:
UserWorkerResponseallocates a newStringforstatus_texton every response, even though the underlying hyper status reasons are static..to_str()UTF-8 validation before mapping to DenoByteString.req_uri.to_string().These allocations cause memory allocator lock contention and CPU overhead under high concurrency.
Please link any relevant issues here.
Resolves #712
What is the new behavior?
This PR refactors these hot-paths to use zero-copy mechanisms to bypass the allocator:
status_textinUserWorkerResponsefromStringto&'static strto map canonical hyper reasons directly to memory without allocation.ByteString, bypassing.to_str()UTF-8 validation overhead..to_string()allocation on request URIs during abort logging with dynamicDisplayformatting.Additional context
Baseline load testing using
k6/specs/simple.tsshows significant improvements after these changes:1.06msto915µs(breaking the sub-millisecond barrier).1.30msto1.15ms.These changes are purely internal optimizations and do not alter any external APIs or behavior.