perf: avoid per-response HttpResponseStatus allocation in statusToNetty#3976
Merged
perf: avoid per-response HttpResponseStatus allocation in statusToNetty#3976
Conversation
The two-arg `HttpResponseStatus.valueOf(code, reasonPhrase)` only returns the cached Netty singleton when the reason phrase matches exactly. Since zio-http's `Status.Ok.reasonPhrase` produces "Ok" (not "OK"), every 200 OK response allocated a new HttpResponseStatus (~80-120 bytes). Switch to the single-arg `valueOf(code)` for non-Custom statuses, which always returns the cached instance. Custom statuses with a non-empty reason phrase still use the two-arg overload.
✅ Deploy Preview for zio-http ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-Authored-By: Jules Ivanic <jules.ivanic@gmail.com>
Custom status codes now always go through valueOf(code, reasonPhrase) to preserve the exact reason phrase. Only standard status codes use the single-arg valueOf(code) for cache hits. Fixes RoundtripSpec failures where Custom(999, "") was being converted to Custom(999, "Unknown Status (999)") via Netty's default reason. Co-Authored-By: Jules Ivanic <jules.ivanic@gmail.com>
Co-Authored-By: Jules Ivanic <jules.ivanic@gmail.com>
987Nabil
approved these changes
Mar 2, 2026
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.
Summary
statusToNettyused the two-argHttpResponseStatus.valueOf(code, reasonPhrase)which only returns Netty's cached singleton when the reason phrase matches exactly. SinceStatus.Ok.reasonPhraseproduces"Ok"(not"OK"), every 200 OK response allocated a newHttpResponseStatusobject (~80-120 bytes).valueOf(code)for non-Custom statuses, which always returns the cached instance. Custom statuses with non-empty reason phrases still use the two-arg overload to preserve user-specified phrases.Test plan
sbt 'zioHttpJVM/testOnly zio.http.netty.model.ConversionsSpec'passes