presentations



presentations

1 0


presentations

All my presentations

On Github romanowski / presentations

Krzysztof Romanowski

romanowski.kr@gmail.com

romanowski RomanowskiKr

Incremental Compiler:

taming Scalac

Plan

Incremental compiler: why? Incremental compiler: do it yourself What was changed? What is affected? In the scope of name Can we do better?

Incremental compiler, why?

cos Scala compilation is

SLOOOW*

*compared to java

more advanced static typed languages (e.g. C#, ... ) are also slow

Let's compile more

Usages graphs... TODO

Incremental compiler:

do it yourself

Algorithm:

do
    Detect changes //TODO
    Select affected subset of sources //TODO
    Compile affected sources // scalac.compile(sources) - DONE
while there are changes to process

Simple?

Do we need recursion?

// Team.scala
class Team {
    def room = "1" // change to 1
}

// User.scala
class User(team: Team) {
    val room: String = team.room // this must fail
}

Can incremental compilation be slower then full build?

object A { def a1 = 1 } // A.scala

object B { def b1 = A.a1 } // B.scala

object C { def c1 = B.b1 } // C.scala

object D { def d1 = C.c1 } // D.scala
[info] Compiling 1 Scala source
[info] Compiling 2 Scala sources
[info] Compiling 2 Scala sources
[info] Compiling 4 Scala sources

Why do we compiler 4 sources in the end?

I have never seen such slowdown on production code (without bug in compiler itself).

What was changed?

Class (file) is changed when

It's source file changed It's not-private API changed

How to detect API changes?

signatures from .class files?

//TODO example

scalap?

//TODO example

scala reflect?

//TODO compiler plugin

do
    // Done - detect changed hashes of source or non-private apo
    Detect changes
    // TODO
    Select affected subset of sources
    // Done - scalac.compile(sources)
    Compile affected sources
while there are changes to process

any other ideas?

What is affected?

Example file TODO

*.class files?

//TODO example

scalap?

//TODO example

Concerete usages vs. potential usage

//TODO examples

Scala reflect - FTW?

//TODO example

do
    // Done - detect changed hashes of source or non-private apo
    Detect changes
    // Done - Traverse tree and add all sources for all used symbols
    Select affected subset of sources
    // Done - scalac.compile(sources)
    Compile affected sources
while there are changes to process

SBT - basic approach

//pseudo code for compile

            //pseudo code for changed sources
            //pseudo code for changed sources

SBT - name hashing

//pseudo code for compile

            //changes in API handling
            //changes in dependecies handling

Can we do better?

Smaller granulation

https://github.com/sbt/zinc/pull/86

Speed vs. Precision

//TODO examples

Speed-up your incremental compilation in 3 steps

Provide return types

One file - few classes

Les wildcard imports

Krzysztof Romanowski

romanowski.kr@gmail.com

romanowski RomanowskiKr

Krzysztof Romanowski romanowski.kr@gmail.com romanowski RomanowskiKr