Low-hanging perf improvements (#10462)

- avoid loading shapeless for the sole purpose of having a compile-time
type inequality
- don't use `sys.env` to avoid some Scala conversions
- lazy initialization of fields

# Important Notes
On a slow machine, so easier to spot.

![Screenshot from 2024-07-05 16-15-06](https://github.com/enso-org/enso/assets/292128/a07f42c5-9bee-492b-aad1-46fab7b6476f)
![Screenshot from 2024-07-05 18-14-53](https://github.com/enso-org/enso/assets/292128/694c4fb1-dfda-4629-8bd3-21c765612ec3)
This commit is contained in:
Hubert Plociniczak 2024-07-08 11:05:11 +02:00 committed by GitHub
parent 018d4c312f
commit 53eec66eda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 15 deletions

View File

@ -548,7 +548,6 @@ val scalacticVersion = "3.3.0-SNAP4"
val scalaLoggingVersion = "3.9.4"
val scalameterVersion = "0.19"
val scalatestVersion = "3.3.0-SNAP4"
val shapelessVersion = "2.3.10"
val slf4jVersion = JPMSUtils.slf4jVersion
val sqliteVersion = "3.42.0.0"
val tikaVersion = "2.4.1"
@ -2226,7 +2225,6 @@ lazy val `runtime-compiler` =
annotationProcSetting,
(Test / fork) := true,
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % shapelessVersion % "provided",
"junit" % "junit" % junitVersion % Test,
"com.github.sbt" % "junit-interface" % junitIfVersion % Test,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,

View File

@ -64,7 +64,7 @@ import java.net.URI
import java.nio.charset.StandardCharsets
import java.time.Clock
import scala.concurrent.duration._
import scala.concurrent.duration.DurationInt
/** A main module containing all components of the server.
*
@ -91,7 +91,7 @@ class MainModule(serverConfig: LanguageServerConfig, logLevel: Level) {
new File(serverConfig.contentRootPath)
)
private val openAiKey = sys.env.get("OPENAI_API_KEY")
private val openAiKey = Option(java.lang.System.getenv("OPENAI_API_KEY"))
private val openAiCfg = openAiKey.map(AICompletionConfig)
val languageServerConfig = Config(

View File

@ -5,7 +5,6 @@ import org.enso.compiler.core.{CompilerError, IR, Identifier}
import org.enso.compiler.core.ir.ProcessingPass
import org.enso.compiler.core.ir.Module
import org.enso.compiler.core.ir.Expression
import shapeless.=:!=
import java.util.UUID
import scala.annotation.unused
@ -129,7 +128,7 @@ object IRPass {
* @return `ev`, cast to `T` if it is a `T`
*/
def as[T <: Metadata: ClassTag](implicit
@unused ev: T =:!= Metadata
@unused ev: T =!= Metadata
): Option[T] = {
this match {
case p: T => Some(p)
@ -146,7 +145,7 @@ object IRPass {
*/
@throws[CompilerError]
def unsafeAs[T <: Metadata: ClassTag](implicit
@unused ev: T =:!= Metadata
@unused ev: T =!= Metadata
): T = {
this
.as[T]
@ -183,4 +182,18 @@ object IRPass {
override def duplicate(): Option[Metadata] = Some(this)
}
}
// https://stackoverflow.com/questions/6909053/enforce-type-difference
sealed class =!=[A, B]
trait LowerPriorityImplicits {
implicit def equal[A]: =!=[A, A] = sys.error("should not be called")
}
object =!= extends LowerPriorityImplicits {
implicit def nequal[A, B](implicit same: A =:= B = null): =!=[A, B] =
if (same != null)
sys.error("should not be called explicitly with same type")
else new =!=[A, B]
}
}

View File

@ -418,20 +418,21 @@ case object LambdaConsolidate extends IRPass {
): List[DefinitionArgument] = {
argsWithShadowed.map {
case (
spec @ DefinitionArgument.Specified(name, _, _, _, _, _, _),
spec: DefinitionArgument.Specified,
isShadowed
) =>
val oldName = spec.name
val newName =
if (isShadowed) {
freshNameSupply
.newName(from = Some(name))
.newName(from = Some(oldName))
.copy(
location = name.location,
passData = name.passData,
diagnostics = name.diagnostics,
id = name.getId
location = oldName.location,
passData = oldName.passData,
diagnostics = oldName.diagnostics,
id = oldName.getId
)
} else name
} else oldName
spec.copy(name = newName)
}

View File

@ -35,7 +35,7 @@ import java.nio.file.Path
*/
class ThreadSafeFileLockManager(locksRoot: Path) extends ThreadSafeLockManager {
val fileLockManager = new FileLockManager(locksRoot)
val localLocks =
lazy val localLocks =
collection.concurrent.TrieMap.empty[String, ThreadSafeLock]
/** A thread-safe wrapper for a file lock - ensures that the process holds at