Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow performance in a combination of features #18763

Open
kubukoz opened this issue Oct 25, 2023 · 10 comments
Open

Slow performance in a combination of features #18763

kubukoz opened this issue Oct 25, 2023 · 10 comments
Labels
area:infer area:typer backlog No work planned on this by the core team for the time being. help wanted itype:enhancement itype:performance stat:needs minimization Needs a self contained minimization

Comments

@kubukoz
Copy link
Contributor

kubukoz commented Oct 25, 2023

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.

@kubukoz kubukoz added the stat:needs triage Every issue needs to have an "area" and "itype" label label Oct 25, 2023
@nicolasstucki nicolasstucki added the stat:needs minimization Needs a self contained minimization label Oct 26, 2023
@sjrd sjrd added itype:enhancement area:typer itype:performance backlog No work planned on this by the core team for the time being. area:infer stat:needs minimization Needs a self contained minimization and removed stat:needs minimization Needs a self contained minimization stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 30, 2023
@sjrd
Copy link
Member

sjrd commented Oct 30, 2023

Mixing type inference, higher-kinded types and implicits leads to difficult situations. Getting rid of one of those 3 factors, such as adding explicit types, seems to be the right thing to do, here.

It could be improved in the future but it is unlikely that this will be worked on by the core team.

@odersky
Copy link
Contributor

odersky commented Oct 31, 2023

@kubukoz We are currently lacking the resources to take on hard stuff like this issue. The Scala Center has launched a fund-raising campaign. If that is successful it would change the situation. We could hopefully work on this if new advisory board members find it important.

@kubukoz
Copy link
Contributor Author

kubukoz commented Oct 31, 2023

Thanks, I appreciate the information!

@smarter
Copy link
Member

smarter commented Nov 1, 2023

It'd be interesting to run async-profiler or jfr on the running compiler to try to see if there's an obvious culprit

@kubukoz
Copy link
Contributor Author

kubukoz commented Nov 1, 2023

Good idea, I shall try that.

@filipwiech
Copy link

Hey @kubukoz, there were some improvements made to the performance of implicit search in #19563. Not sure, but maybe there's a chance that it helped with this issue as well? 🙂

@kubukoz
Copy link
Contributor Author

kubukoz commented Jan 31, 2024

That sounds promising. I'll test when I find a moment :)

@kubukoz
Copy link
Contributor Author

kubukoz commented May 17, 2024

Still takes about 7 seconds to compile in 3.4.2.

@matthughes
Copy link

Would be great if compiler could report on time spent compiling each artifact. I'm happy to add explicit types, etc but how would you even know this was an issue in a project of 1000 source files?

@filipwiech
Copy link

I'm patiently waiting for the #19897 to land. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:infer area:typer backlog No work planned on this by the core team for the time being. help wanted itype:enhancement itype:performance stat:needs minimization Needs a self contained minimization
Projects
None yet
Development

No branches or pull requests

8 participants