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)
This commit is contained in:
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.config.Services
|
|||||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||||
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
||||||
import org.jetbrains.kotlin.rmi.*
|
import org.jetbrains.kotlin.rmi.*
|
||||||
|
import java.io.BufferedOutputStream
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
import java.rmi.NoSuchObjectException
|
import java.rmi.NoSuchObjectException
|
||||||
import java.rmi.registry.Registry
|
import java.rmi.registry.Registry
|
||||||
@@ -130,12 +131,18 @@ class CompileServiceImpl(
|
|||||||
private fun doCompile(args: Array<out String>, compilerMessagesStreamProxy: RemoteOutputStream, serviceOutputStreamProxy: RemoteOutputStream, body: (PrintStream, Profiler) -> ExitCode): Int =
|
private fun doCompile(args: Array<out String>, compilerMessagesStreamProxy: RemoteOutputStream, serviceOutputStreamProxy: RemoteOutputStream, body: (PrintStream, Profiler) -> ExitCode): Int =
|
||||||
ifAlive {
|
ifAlive {
|
||||||
val rpcProfiler = if (daemonOptions.reportPerf) WallAndThreadTotalProfiler() else DummyProfiler()
|
val rpcProfiler = if (daemonOptions.reportPerf) WallAndThreadTotalProfiler() else DummyProfiler()
|
||||||
val compilerMessagesStream = PrintStream(RemoteOutputStreamClient(compilerMessagesStreamProxy, rpcProfiler))
|
val compilerMessagesStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(compilerMessagesStreamProxy, rpcProfiler), 4096))
|
||||||
val serviceOutputStream = PrintStream(RemoteOutputStreamClient(serviceOutputStreamProxy, rpcProfiler))
|
val serviceOutputStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(serviceOutputStreamProxy, rpcProfiler), 4096))
|
||||||
checkedCompile(args, serviceOutputStream, rpcProfiler) {
|
try {
|
||||||
val res = body( compilerMessagesStream, rpcProfiler).code
|
checkedCompile(args, serviceOutputStream, rpcProfiler) {
|
||||||
_lastUsedSeconds = nowSeconds()
|
val res = body(compilerMessagesStream, rpcProfiler).code
|
||||||
res
|
_lastUsedSeconds = nowSeconds()
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
serviceOutputStream.flush()
|
||||||
|
compilerMessagesStream.flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -20,10 +20,19 @@ import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
|||||||
import org.jetbrains.kotlin.rmi.CompilerCallbackServicesFacade
|
import org.jetbrains.kotlin.rmi.CompilerCallbackServicesFacade
|
||||||
import org.jetbrains.kotlin.rmi.DummyProfiler
|
import org.jetbrains.kotlin.rmi.DummyProfiler
|
||||||
import org.jetbrains.kotlin.rmi.Profiler
|
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 {
|
class RemoteCompilationCanceledStatusClient(val facade: CompilerCallbackServicesFacade, val profiler: Profiler = DummyProfiler()): CompilationCanceledStatus {
|
||||||
|
@Volatile var lastChecked: Long = System.nanoTime()
|
||||||
override fun checkCanceled() {
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user