From 6a7c5e15763c6e61eb35e5a09771969eaccc1c9b Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Wed, 7 Oct 2015 12:56:45 +0200 Subject: [PATCH] Reducing overhead of rpc callbacks by 1) subsampling cancelled status check (had severe impact), and 2) using buffered remote message streams (had less but still noticeable impact) --- .../kotlin/rmi/service/CompileServiceImpl.kt | 19 +++++++++++++------ .../RemoteCompilationCanceledStatusClient.kt | 11 ++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileServiceImpl.kt b/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileServiceImpl.kt index 8da7cbee995..b1a323ffbac 100644 --- a/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileServiceImpl.kt +++ b/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileServiceImpl.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents import org.jetbrains.kotlin.progress.CompilationCanceledStatus import org.jetbrains.kotlin.rmi.* +import java.io.BufferedOutputStream import java.io.PrintStream import java.rmi.NoSuchObjectException import java.rmi.registry.Registry @@ -130,12 +131,18 @@ class CompileServiceImpl( private fun doCompile(args: Array, compilerMessagesStreamProxy: RemoteOutputStream, serviceOutputStreamProxy: RemoteOutputStream, body: (PrintStream, Profiler) -> ExitCode): Int = ifAlive { val rpcProfiler = if (daemonOptions.reportPerf) WallAndThreadTotalProfiler() else DummyProfiler() - val compilerMessagesStream = PrintStream(RemoteOutputStreamClient(compilerMessagesStreamProxy, rpcProfiler)) - val serviceOutputStream = PrintStream(RemoteOutputStreamClient(serviceOutputStreamProxy, rpcProfiler)) - checkedCompile(args, serviceOutputStream, rpcProfiler) { - val res = body( compilerMessagesStream, rpcProfiler).code - _lastUsedSeconds = nowSeconds() - res + val compilerMessagesStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(compilerMessagesStreamProxy, rpcProfiler), 4096)) + val serviceOutputStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(serviceOutputStreamProxy, rpcProfiler), 4096)) + try { + checkedCompile(args, serviceOutputStream, rpcProfiler) { + val res = body(compilerMessagesStream, rpcProfiler).code + _lastUsedSeconds = nowSeconds() + res + } + } + finally { + serviceOutputStream.flush() + compilerMessagesStream.flush() } } diff --git a/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/RemoteCompilationCanceledStatusClient.kt b/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/RemoteCompilationCanceledStatusClient.kt index 056aa640b89..d3f9a430cb0 100644 --- a/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/RemoteCompilationCanceledStatusClient.kt +++ b/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/RemoteCompilationCanceledStatusClient.kt @@ -20,10 +20,19 @@ import org.jetbrains.kotlin.progress.CompilationCanceledStatus import org.jetbrains.kotlin.rmi.CompilerCallbackServicesFacade import org.jetbrains.kotlin.rmi.DummyProfiler import org.jetbrains.kotlin.rmi.Profiler +import java.util.concurrent.TimeUnit +val CANCELED_STATUS_CHECK_THRESHOLD_NS = TimeUnit.MILLISECONDS.toNanos(100) class RemoteCompilationCanceledStatusClient(val facade: CompilerCallbackServicesFacade, val profiler: Profiler = DummyProfiler()): CompilationCanceledStatus { + @Volatile var lastChecked: Long = System.nanoTime() override fun checkCanceled() { - profiler.withMeasure(this) { facade.compilationCanceledStatus_checkCanceled() } + val curNanos = System.nanoTime() + if (curNanos - lastChecked > CANCELED_STATUS_CHECK_THRESHOLD_NS) { + profiler.withMeasure(this) { + facade.compilationCanceledStatus_checkCanceled() + } + lastChecked = curNanos + } } }