Skip to content

Commit 4e9cf7a

Browse files
committed
perf: optimize DSPLaunchDelegate OutputStream wrapper
This PR implements the `OutputStream.write(byte[] b, int off, int len)` method for the anonymous inner OutputStream wrapper class to avoid excessive string allocations on each written byte.
1 parent 7479a52 commit 4e9cf7a

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

org.eclipse.lsp4e.debug/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
33
Bundle-Name: Debug Adapter client for Eclipse IDE (Incubation)
44
Bundle-SymbolicName: org.eclipse.lsp4e.debug;singleton:=true
55
Bundle-Vendor: Eclipse LSP4E
6-
Bundle-Version: 0.15.15.qualifier
6+
Bundle-Version: 0.15.16.qualifier
77
Bundle-Activator: org.eclipse.lsp4e.debug.DSPPlugin
88
Require-Bundle: org.eclipse.ui,
99
org.eclipse.core.runtime,

org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/launcher/DSPLaunchDelegate.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.eclipse.debug.core.model.IDebugTarget;
3737
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
3838
import org.eclipse.debug.core.model.IProcess;
39+
import org.eclipse.debug.core.model.IStreamsProxy;
3940
import org.eclipse.jdt.annotation.Nullable;
4041
import org.eclipse.lsp4e.debug.DSPPlugin;
4142
import org.eclipse.lsp4e.debug.debugmodel.DSPDebugTarget;
@@ -193,8 +194,8 @@ public Map<String, Object> getDspParameters() {
193194
public String toString() {
194195
return "DSPLaunchDelegateLaunchBuilder [configuration=" + configuration + ", mode=" + mode + ", launch="
195196
+ launch + ", monitor=" + monitor + ", launchNotConnect=" + launchNotConnect + ", debugCmd="
196-
+ debugCmd + ", debugCmdArgs=" + debugCmdArgs //
197-
+ ", debugCmdEnvVars=" + (debugCmdEnvVars == null ? null : List.of(debugCmdEnvVars))
197+
+ debugCmd + ", debugCmdArgs=" + debugCmdArgs //
198+
+ ", debugCmdEnvVars=" + (debugCmdEnvVars == null ? null : List.of(debugCmdEnvVars))
198199
+ ", monitorDebugAdapter=" + monitorDebugAdapter + ", server=" + server + ", port=" + port
199200
+ ", dspParameters=" + dspParameters + "]";
200201
}
@@ -303,6 +304,7 @@ public void launch(DSPLaunchDelegateLaunchBuilder builderSrc) throws CoreExcepti
303304
builder.launch.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, Boolean.toString(true));
304305
IProcess debugAdapterIProcess = DebugPlugin.newProcess(builder.launch, debugAdapterProcess,
305306
"Debug Adapter");
307+
final IStreamsProxy debugAdapterStreamsProxy = castNonNull(debugAdapterIProcess.getStreamsProxy());
306308
builder.launch.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, initialCaptureOutput);
307309

308310
final var bytes = new ConcurrentLinkedQueue<Byte>();
@@ -329,17 +331,20 @@ public int read() throws IOException {
329331
final var consoleCharset = consoleEncoding == null //
330332
? Charset.defaultCharset()
331333
: Charset.forName(consoleEncoding);
332-
castNonNull(castNonNull(debugAdapterIProcess.getStreamsProxy()).getOutputStreamMonitor())
333-
.addListener((text, monitor) -> {
334-
for (byte b : text.getBytes(consoleCharset)) {
335-
bytes.add(b);
336-
}
337-
});
334+
castNonNull(debugAdapterStreamsProxy.getOutputStreamMonitor()).addListener((text, monitor) -> {
335+
for (byte b : text.getBytes(consoleCharset)) {
336+
bytes.add(b);
337+
}
338+
});
338339
outputStream = new OutputStream() {
339340
@Override
340341
public void write(int b) throws IOException {
341-
castNonNull(debugAdapterIProcess.getStreamsProxy())
342-
.write(new String(new byte[] { (byte) b }));
342+
debugAdapterStreamsProxy.write(new String(new byte[] { (byte) b }));
343+
}
344+
345+
@Override
346+
public void write(byte[] b, int off, int len) throws IOException {
347+
debugAdapterStreamsProxy.write(new String(b, off, len));
343348
}
344349
};
345350
cleanup = () -> {

0 commit comments

Comments
 (0)