Merge pull request #5796 from eatkins/network-channel-memory

Reduce sbt memory utilization
This commit is contained in:
eugene yokota
2020-08-24 15:23:09 -04:00
committed by GitHub
2 changed files with 11 additions and 13 deletions
@@ -195,13 +195,10 @@ private[sbt] final class CommandExchange {
new NetworkChannel( new NetworkChannel(
name, name,
socket, socket,
Project structure s,
auth, auth,
instance, instance,
handlers, handlers,
s.log,
mkAskUser(name), mkAskUser(name),
Option(lastState.get),
) )
subscribe(channel) subscribe(channel)
} }
@@ -54,13 +54,10 @@ import sbt.internal.util.ProgressState
final class NetworkChannel( final class NetworkChannel(
val name: String, val name: String,
connection: Socket, connection: Socket,
protected val structure: BuildStructure,
auth: Set[ServerAuthentication], auth: Set[ServerAuthentication],
instance: ServerInstance, instance: ServerInstance,
handlers: Seq[ServerHandler], handlers: Seq[ServerHandler],
val log: Logger,
mkUIThreadImpl: (State, CommandChannel) => UITask, mkUIThreadImpl: (State, CommandChannel) => UITask,
state: Option[State],
) extends CommandChannel { self => ) extends CommandChannel { self =>
def this( def this(
name: String, name: String,
@@ -74,15 +71,14 @@ final class NetworkChannel(
this( this(
name, name,
connection, connection,
structure,
auth, auth,
instance, instance,
handlers, handlers,
log,
new UITask.AskUserTask(_, _), new UITask.AskUserTask(_, _),
None
) )
def log: Logger = StandardMain.exchange.withState(_.log)
private val running = new AtomicBoolean(true) private val running = new AtomicBoolean(true)
private val delimiter: Byte = '\n'.toByte private val delimiter: Byte = '\n'.toByte
private val out = connection.getOutputStream private val out = connection.getOutputStream
@@ -411,9 +407,12 @@ final class NetworkChannel(
protected def onSettingQuery(execId: Option[String], req: SettingQuery) = { protected def onSettingQuery(execId: Option[String], req: SettingQuery) = {
if (initialized) { if (initialized) {
import sbt.protocol.codec.JsonProtocol._ import sbt.protocol.codec.JsonProtocol._
SettingQuery.handleSettingQueryEither(req, structure) match { StandardMain.exchange.withState { s =>
case Right(x) => respondResult(x, execId) val structure = Project.extract(s).structure
case Left(s) => respondError(ErrorCodes.InvalidParams, s, execId) SettingQuery.handleSettingQueryEither(req, structure) match {
case Right(x) => respondResult(x, execId)
case Left(s) => respondError(ErrorCodes.InvalidParams, s, execId)
}
} }
} else { } else {
log.warn(s"ignoring query $req before initialization") log.warn(s"ignoring query $req before initialization")
@@ -792,7 +791,9 @@ final class NetworkChannel(
private[this] val blockedThreads = ConcurrentHashMap.newKeySet[Thread] private[this] val blockedThreads = ConcurrentHashMap.newKeySet[Thread]
override private[sbt] val progressState: ProgressState = new ProgressState( override private[sbt] val progressState: ProgressState = new ProgressState(
1, 1,
state.flatMap(_.get(Keys.superShellMaxTasks.key)).getOrElse(SysProp.supershellMaxTasks) StandardMain.exchange
.withState(_.get(Keys.superShellMaxTasks.key))
.getOrElse(SysProp.supershellMaxTasks)
) )
override def getWidth: Int = getProperty(_.width, 0).getOrElse(0) override def getWidth: Int = getProperty(_.width, 0).getOrElse(0)
override def getHeight: Int = getProperty(_.height, 0).getOrElse(0) override def getHeight: Int = getProperty(_.height, 0).getOrElse(0)