Skip to content

Slow performance in a combination of features #18763

Open
@kubukoz

Description

@kubukoz

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions