Skip to content

Commit 59c5b89

Browse files
Re-apply the undertow plaintext ByteBuffer optimization (#4019)
Undertow's relative placement in the plaintext test dropped after changing this handler to use a regular string. This coincided with our move to docker and a switch to new benchmarking hardware, so there are certainly other variables in the mix, but it's reasonable to assume the ByteBuffer->string change is partially to blame. Also IIRC it was the Undertow authors themselves who originally wrote the ByteBuffer optimization, so it probably doesn't make sense for me to second guess them.
1 parent d31b937 commit 59c5b89

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

frameworks/Java/undertow/src/main/java/hello/HelloWebServer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hello;
22

33
import static io.undertow.util.Headers.CONTENT_TYPE;
4+
import static java.nio.charset.StandardCharsets.US_ASCII;
45
import static java.util.Comparator.comparing;
56

67
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -84,9 +85,15 @@ static HttpHandler postgresqlPathHandler() {
8485
}
8586

8687
static HttpHandler plaintextHandler() {
88+
var text = "Hello, World!";
89+
var bytes = text.getBytes(US_ASCII);
90+
var buffer = ByteBuffer.allocateDirect(bytes.length)
91+
.put(bytes)
92+
.flip();
93+
8794
return exchange -> {
8895
exchange.getResponseHeaders().put(CONTENT_TYPE, "text/plain");
89-
exchange.getResponseSender().send("Hello, World!");
96+
exchange.getResponseSender().send(buffer.duplicate());
9097
};
9198
}
9299

0 commit comments

Comments
 (0)