Use static INSTANCE singleton for stateless HttpServerResponseMutators#18326
Merged
Conversation
Adds 'static final INSTANCE' field and private constructor to the stateless final-class HttpServerResponseMutator implementations (Grizzly, Helidon, Jetty 8/11/12, Servlet 3) and updates their call sites to use INSTANCE instead of 'new XyzMutator()'. These mutators are invoked from per-response advice / filters / handlers, matching the hot-path exception in general-rules.md ('Prefer Instance Creation Over Singletons'). This also brings them in line with the existing enum-singleton mutators (Armeria, JavaHttpServer, Netty 3.8/4.0/4.1, Tomcat 10, Restlet 1/2, Undertow) and the static-INSTANCE mutators (Tomcat 7, Servlet 2.2). Akka and Pekko mutators are intentionally left unchanged because they hold per-request header state.
laurit
reviewed
Apr 27, 2026
|
|
||
| public class GrizzlyHttpResponseMutator implements HttpServerResponseMutator<HttpResponsePacket> { | ||
|
|
||
| public static final GrizzlyHttpResponseMutator INSTANCE = new GrizzlyHttpResponseMutator(); |
Contributor
There was a problem hiding this comment.
Could consider using the enum singleton as it is more compact, a bunch of HttpServerResponseMutators already use it
Member
Author
There was a problem hiding this comment.
yeah, makes sense
it would be nice to have a consistent story for when / whether we use enum singleton pattern
I did a quick check and looks like we have pretty even split of enum singleton INSTANCE to class singleton INSTANCE.
I'm good with any range of never to always or something in the middle
maybe just embrace them? (except maybe for public library classes in order to preserve flexibility)
laurit
approved these changes
Apr 27, 2026
# Conflicts: # instrumentation/servlet/servlet-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3HttpServerResponseMutator.java
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.
Since they're currently being unnecessarily allocated on the hotpath.