Skip to content

Commit 8827c19

Browse files
committed
perf(jsonrpc): buffer output writes in StreamMessageConsumer
Wrap provided OutputStream in BufferedOutputStream to amortize small writes; improves throughput by reducing syscalls. Centralize wrapping via setOutput to avoid double wrapping.
1 parent 79e2cf7 commit 8827c19

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/StreamMessageConsumer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
******************************************************************************/
1212
package org.eclipse.lsp4j.jsonrpc.json;
1313

14+
import java.io.BufferedOutputStream;
1415
import java.io.IOException;
1516
import java.io.OutputStream;
1617
import java.nio.charset.StandardCharsets;
@@ -29,7 +30,7 @@ public class StreamMessageConsumer implements MessageConsumer, MessageConstants
2930

3031
private final Object outputLock = new Object();
3132

32-
private OutputStream output;
33+
private BufferedOutputStream output;
3334

3435
public StreamMessageConsumer(MessageJsonHandler jsonHandler) {
3536
this(null, StandardCharsets.UTF_8.name(), jsonHandler);
@@ -40,7 +41,7 @@ public StreamMessageConsumer(OutputStream output, MessageJsonHandler jsonHandler
4041
}
4142

4243
public StreamMessageConsumer(OutputStream output, String encoding, MessageJsonHandler jsonHandler) {
43-
this.output = output;
44+
setOutput(output);
4445
this.encoding = encoding;
4546
this.jsonHandler = jsonHandler;
4647
}
@@ -50,7 +51,11 @@ public OutputStream getOutput() {
5051
}
5152

5253
public void setOutput(OutputStream output) {
53-
this.output = output;
54+
this.output = output == null //
55+
? null
56+
: output instanceof BufferedOutputStream //
57+
? (BufferedOutputStream) output
58+
: new BufferedOutputStream(output);
5459
}
5560

5661
@Override

0 commit comments

Comments
 (0)