Giter VIP home page Giter VIP logo

Comments (5)

WojciechMazur avatar WojciechMazur commented on June 20, 2024 5

Thanks to changes in #20399 the compilation times has dropped significantly. In case of original project the compilation times presents as following:

  • Scala 2.13.12: 2min 14s in which typer took 1m 28s
  • Scala 3.5.0-RC1: 7m 26s, in which typer took 6m 06s
  • Scala 3.5.0-RC1-bin-20240516-c608177-NIGHTLY: 2min 44s in which typer took 1min 19s and inlining took 43s

Under -Yprofile-trace I can still find 3 methods that still take long time to compile 2-5s, so there still might be some room for future improvements. I'll try to create a minimisation for these if possible

from scala3.

WojciechMazur avatar WojciechMazur commented on June 20, 2024

During the meeting it was mentioned that #19931 might have fixed this issue, however it seems to have no effect on this particular problem - it has no effect when it comes to compilation times

from scala3.

odersky avatar odersky commented on June 20, 2024

Intersection types should affect compilation times with no more then 20% overhead.

Intersection types can give a worst case exponential blowup of compilation times. So this is a nice goal, but not an achievable one 😉

from scala3.

jchyb avatar jchyb commented on June 20, 2024

I think I reached the end of my abilities here, so I will share my findings so hopefully the next person has an easier time.

  1. The issue is caused by the implicit resolution adding unfulfilled type variables with type bound constraints (>: Repro.ObjectId & Endpoints.this.Foo <: Repro.ObjectId & Endpoints.this.Foo) to typer state in T1 (in T2 they are gc’d when committing that typerState, as the type bounds are not created for the tuple), which later causes typer to take a longer code path like in the variances method, where overall T1 takes around 10x as much time as T2.
  2. I tried to make a quick fix where I remove the bound with equal lo and hi when committing the typer state obtained in the implicit search, but that broke a test where those were added explicitly in the code. It likely breaks other stuff too.
  3. The problematic typer state is generated here in the adapt method when searching for implicits, and the constraint there can look like this (this is the first constraint added when resolving tupleArity[A] for implicit in T1):
uninstantiated variables: J, IJ, J, IJ, J, IJ, A
 constrained types:
  [J, IJ]
    (i: EndpointInput[J])
      (implicit concat:
        ParamConcat.Aux[Repro.ObjectId & Endpoints.this.Foo, J, IJ]):
        Endpoints.this.baseEndpointWithIntersection.EndpointType[
          Repro.AuthInput, IJ, Repro.ApiError, Unit, Any]
  ,
  [J, IJ]
    (i: EndpointInput[J])
      (implicit concat:
        ParamConcat.Aux[Repro.ObjectId & Endpoints.this.Foo, J, IJ]):
        Endpoints.this.baseEndpointWithIntersection.EndpointType[
          Repro.AuthInput, IJ, Repro.ApiError, Unit, Any]
  ,
  [J, IJ]
    (i: EndpointInput[J])
      (implicit concat:
        ParamConcat.Aux[Repro.ObjectId & Endpoints.this.Foo, J, IJ]):
        Endpoints.this.baseEndpointWithIntersection.EndpointType[
          Repro.AuthInput, Repro.ObjectId & Endpoints.this.Foo, Repro.ApiError,
          Unit, Any]#EndpointType[Repro.AuthInput, IJ, Repro.ApiError, Unit, Any
          ]
  ,
  [J, IJ]
    (i: EndpointInput[J])
      (implicit concat:
        ParamConcat.Aux[Repro.ObjectId & Endpoints.this.Foo, J, IJ]):
        Endpoints.this.baseEndpointWithIntersection.EndpointType[
          Repro.AuthInput, Repro.ObjectId & Endpoints.this.Foo, Repro.ApiError,
          Unit, Any]#EndpointType[Repro.AuthInput, IJ, Repro.ApiError, Unit, Any
          ]
  ,
[T](implicit ta: TupleArity[T]): ParamConcat.Aux[T, Unit, T], [A]: TupleArity[A]
 bounds:
     J
     IJ
     J := Unit
     IJ := Repro.ObjectId & Endpoints.this.Foo
     J
     IJ
     J
     IJ
     T := Repro.ObjectId & Endpoints.this.Foo
     A
     >: Repro.ObjectId & Endpoints.this.Foo <: Repro.ObjectId &
      Endpoints.this.Foo
The problematic part is in the list line, if it was `A := Repro.ObjectId & Endpoints.this.Foo` we wouldn’t have the problem. I do not know the exact place where it’s added (this is where I got stuck), but it's in the `adapt` method.

Things I did to make my life easier (maybe they will be useful):

  1. I precompiled scalac -d . Api.scala TypeLevel.scala, so that I could get less printouts from the compiler when compiling scalac -cp /Users/jchyb/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar:/Users/jchyb/workspace/scala3/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.4.2-RC1-bin-SNAPSHOT-nonbootstrapped/scala3-library_3-3.4.2-RC1-bin-SNAPSHOT.jar:. zrepr/Repro.scala

from scala3.

rlecomte avatar rlecomte commented on June 20, 2024

@WojciechMazur I tried to compile the following code with Scala 3.5.0-RC1-bin-20240516-c608177-NIGHTLY and I got a significant raise of compilation time.

  • Scala 2.13.14: ~1s
  • Scala 3.4.1: ~40s
  • 3.5.0-RC1-bin-20240516-c608177-NIGHTLY: 420s
object Main {
  trait A {}
  trait B {}
  trait C {}
  trait D {}
  trait E {}
  trait F {}
  trait G {}
  trait H {}
  trait I {}
  trait J {}
  trait K {}
  trait L {}
  trait M {}
  trait N {}
  trait O {}
  trait P {}
  trait Q {}
  trait R {}
  trait S {}
  trait T {}
  trait U {}
  trait V {}
  trait W {}
  trait X {}
  trait Y {}
  trait Z {}

  type AlphabeticServices = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z

  type EnvOutA = B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutB = A & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutC = A & B & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutD = A & B & C & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutE = A & B & C & D & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutF = A & B & C & D & E & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutG = A & B & C & D & E & F & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutH = A & B & C & D & E & F & G & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutI = A & B & C & D & E & F & G & H & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutJ = A & B & C & D & E & F & G & H & I & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutK = A & B & C & D & E & F & G & H & I & J & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutL = A & B & C & D & E & F & G & H & I & J & K & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutM = A & B & C & D & E & F & G & H & I & J & K & L & N & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutN = A & B & C & D & E & F & G & H & I & J & K & L & M & O & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutO = A & B & C & D & E & F & G & H & I & J & K & L & M & N & P & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutP = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & Q & R & S & T & U & V & W & X & Y & Z
  type EnvOutQ = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & R & S & T & U & V & W & X & Y & Z
  type EnvOutR = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & S & T & U & V & W & X & Y & Z
  type EnvOutS = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & T & U & V & W & X & Y & Z
  type EnvOutT = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & U & V & W & X & Y & Z
  type EnvOutU = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & V & W & X & Y & Z
  type EnvOutV = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & W & X & Y & Z
  type EnvOutW = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & X & Y & Z
  type EnvOutX = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & Y & Z
  type EnvOutY = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Z
  type EnvOutZ = A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y

  trait Reader[-E, A] {
    def map[B](f: A => B): Reader[E, B] = ???
    def flatMap[E2 <: E, B](f: A => Reader[E2, B]): Reader[E2, B] = ???
  }

  def e1: Reader[EnvOutA, Unit] = ???
  def e2: Reader[EnvOutB, Unit] = ???
  def e3: Reader[EnvOutC, Unit] = ???
  def e4: Reader[EnvOutD, Unit] = ???
  def e5: Reader[EnvOutE, Unit] = ???
  def e6: Reader[EnvOutF, Unit] = ???
  def e7: Reader[EnvOutG, Unit] = ???
  def e8: Reader[EnvOutH, Unit] = ???
  def e9: Reader[EnvOutI, Unit] = ???
  def e10: Reader[EnvOutJ, Unit] = ???
  def e11: Reader[EnvOutK, Unit] = ???
  def e12: Reader[EnvOutL, Unit] = ???
  def e13: Reader[EnvOutM, Unit] = ???
  def e14: Reader[EnvOutN, Unit] = ???
  def e15: Reader[EnvOutO, Unit] = ???
  def e16: Reader[EnvOutP, Unit] = ???
  def e17: Reader[EnvOutQ, Unit] = ???
  def e18: Reader[EnvOutR, Unit] = ???
  def e19: Reader[EnvOutS, Unit] = ???
  def e20: Reader[EnvOutT, Unit] = ???
  def e21: Reader[EnvOutU, Unit] = ???
  def e22: Reader[EnvOutV, Unit] = ???
  def e23: Reader[EnvOutW, Unit] = ???
  def e24: Reader[EnvOutX, Unit] = ???
  def e25: Reader[EnvOutY, Unit] = ???
  def e26: Reader[EnvOutZ, Unit] = ???

  def program: Reader[AlphabeticServices, Unit] = for {
        //1
    _ <- e1
    _ <- e2
    _ <- e3
    _ <- e4
    _ <- e5
    _ <- e6
    _ <- e7
    _ <- e8
    _ <- e8
    _ <- e9
    _ <- e10
    _ <- e11
    _ <- e12
    _ <- e13
    _ <- e14
    _ <- e15
    _ <- e16
    _ <- e17
    _ <- e18
    _ <- e19
    _ <- e20
    _ <- e21
    _ <- e22
    _ <- e23
    _ <- e24
    _ <- e25
    _ <- e26
    //2
    _ <- e1
    _ <- e2
    _ <- e3
    _ <- e4
    _ <- e5
    _ <- e6
    _ <- e7
    _ <- e8
    _ <- e8
    _ <- e9
    _ <- e10
    _ <- e11
    _ <- e12
    _ <- e13
    _ <- e14
    _ <- e15
    _ <- e16
    _ <- e17
    _ <- e18
    _ <- e19
    _ <- e20
    _ <- e21
    _ <- e22
    _ <- e23
    _ <- e24
    _ <- e25
    _ <- e26
    //3
    _ <- e1
    _ <- e2
    _ <- e3
    _ <- e4
    _ <- e5
    _ <- e6
    _ <- e7
    _ <- e8
    _ <- e8
    _ <- e9
    _ <- e10
    _ <- e11
    _ <- e12
    _ <- e13
    _ <- e14
    _ <- e15
    _ <- e16
    _ <- e17
    _ <- e18
    _ <- e19
    _ <- e20
    _ <- e21
    _ <- e22
    _ <- e23
    _ <- e24
    _ <- e25
    _ <- e26
    //4
    _ <- e1
    _ <- e2
    _ <- e3
    _ <- e4
    _ <- e5
    _ <- e6
    _ <- e7
    _ <- e8
    _ <- e8
    _ <- e9
    _ <- e10
    _ <- e11
    _ <- e12
    _ <- e13
    _ <- e14
    _ <- e15
    _ <- e16
    _ <- e17
    _ <- e18
    _ <- e19
    _ <- e20
    _ <- e21
    _ <- e22
    _ <- e23
    _ <- e24
    _ <- e25
    _ <- e26
    } yield ()
}

from scala3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.