scala/scala3

Slow performance in a combination of features

Open

#18.763 geöffnet am 25. Okt. 2023

Auf GitHub ansehen
 (12 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Scala (1.159 Forks)batch import
area:inferarea:typerbackloghelp wanteditype:enhancementitype:performancestat:needs minimization

Repository-Metriken

Stars
 (6.247 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 18T 14h) (133 gemergte PRs in 30 T)

Beschreibung

Compiler version

3.3.1, 3.4.0-RC1-bin-20231024-15033c7-NIGHTLY

Minimized example

//> using scala "3.4.0-RC1-bin-20231024-15033c7-NIGHTLY"
//> using lib "org.typelevel::cats-effect:3.5.2"
package demo

import cats.effect.IO
import cats.effect.kernel.Resource
import cats.implicits._

val demo: Resource[IO, Unit] = Resource.unit.as(???)

Output

Takes ~7s to compile on an M1 Max machine, ~18s in Scastie.

Expectation

Compiles as fast as this:

//> using scala "3.4.0-RC1-bin-20231024-15033c7-NIGHTLY"
//> using lib "org.typelevel::cats-effect:3.5.2"
package demo

import cats.effect.IO
import cats.effect.kernel.Resource
import cats.implicits._

val demo: Resource[IO, Unit] = Resource.unit[IO].as(???)

which is under a second on my machine.

Extra context

  • unit's signature is def unit[F[_]]: Resource[F, Unit]
  • as is a method coming from an implicit conversion, which is brought in via cats.implicits._
  • The code doesn't compile on Scala 2.13 because unit's parameter is simply not inferred at all (I suppose it's just the new inference algorithm)

I believe the slowdown is a combination of trying to infer unit's type parameter (which is a type constructor, potentially complicating inference) from a Scala 2 implicit conversion.

The main problem with this issue is that it's not only slowing down the actual compilation process (for my runs or tests), but also affecting all Metals functionality - completions timing out and similar.

Contributor Guide