2012 Miguel Garcia walked into my office and said: “From a low-level perspective, there are only values and pointers. Maybe you can use that!” ... LONG DOUBLE INT FLOAT SHORT
2012 Miguel Garcia walked into my office and said: “From a low-level perspective, there are only values and pointers. Maybe you can use that!” ... LONG DOUBLE INT FLOAT SHORT a long integer
def r(t: Repr): Double // red def g(t: Repr): Double // green def b(t: Repr): Double // blue def a(t: Repr): Double // alpha def pack(r: Double, g: Double, b: Double, a: Double): Repr ... } All transformations work on double precision FP numbers But the data can be encoded differently
"miniboxing-runtime" % "0.4-SNAPSHOT" addCompilerPlugin("org.scala-miniboxing.plugins" %% "miniboxing-plugin" % "0.4-SNAPSHOT") Release 0.4 in the works now
into @miniboxed "-P:minibox:mark-all" :: // mark all type parameters as @miniboxed "-P:minibox:log" :: // explain how classes are transformed "-P:minibox:warn" :: // warn for suboptimal code "-P:minibox:warn-all" :: // warn for suboptimal code across projects Nil
into @miniboxed "-P:minibox:mark-all" :: // mark all type parameters as @miniboxed "-P:minibox:log" :: // explain how classes are transformed "-P:minibox:warn" :: // warn for suboptimal code "-P:minibox:warn-all" :: // warn for suboptimal code across projects Nil Huh? What's the difference?
Nil // under -P:minibox:warn res0: List[Int] = List(3) scala> 3 :: Nil // under -P:minibox:warn-all <console>:8: warning: The method List.:: would benefit from miniboxing type parameter B, since it is instantiated by a primitive type. 3 :: Nil ^ res0: List[Int] = List(3)
Nil // under -P:minibox:warn res0: List[Int] = List(3) scala> 3 :: Nil // under -P:minibox:warn-all <console>:8: warning: The method List.:: would benefit from miniboxing type parameter B, since it is instantiated by a primitive type. 3 :: Nil ^ res0: List[Int] = List(3)
Nil // under -P:minibox:warn res0: List[Int] = List(3) scala> 3 :: Nil // under -P:minibox:warn-all <console>:8: warning: The method List.:: would benefit from miniboxing type parameter B, since it is instantiated by a primitive type. 3 :: Nil ^ res0: List[Int] = List(3) Warning for the scala library :)
Nil // under -P:minibox:warn res0: List[Int] = List(3) scala> 3 :: Nil // under -P:minibox:warn-all <console>:8: warning: The method List.:: would benefit from miniboxing type parameter B, since it is instantiated by a primitive type. 3 :: Nil ^ res0: List[Int] = List(3) Warning for the scala library :) Across projects, not limited to the program being compiled.
performance (on the JVM) is magic • specialization (in scalac) is black magic – “know the conditions of specialization” – point n: “Use Traits” – point n+1: “Don't use Traits” – … and other 10 pieces of advice ... – is your code running at max performance? • who knows?
performance (on the JVM) is magic • specialization (in scalac) is black magic – “know the conditions of specialization” – point n: “Use Traits” – point n+1: “Don't use Traits” – … and other 10 pieces of advice ... – is your code running at max performance? • who knows? Can we do something about this?
identity("3") res2: String = 3 scala> identity[Any](3) <console>:9: warning: Using the type argument "Any" for the miniboxed type parameter T of method identity is not specific enough, as it could mean either a primitive or a reference type. Although method foo is miniboxed, it won't benefit from specialization: identity[Any](3) ^ res3: Any = 3
identity("3") res2: String = 3 scala> identity[Any](3) <console>:9: warning: Using the type argument "Any" for the miniboxed type parameter T of method identity is not specific enough, as it could mean either a primitive or a reference type. Although method foo is miniboxed, it won't benefit from specialization: identity[Any](3) ^ res3: Any = 3 what if identity wasn't miniboxed?
[T](t: T)T scala> def bar[T](t: T) = foo(t) bar: [T](t: T)T scala> bar(3) <console>:10: warning: The method bar would benefit from miniboxing type parameter T, since it is instantiated by a primitive type. bar(3) ^ res1: Int = 3
[T](t: T)T bar is generic, let's add @miniboxed scala> def bar[T](t: T) = foo(t) bar: [T](t: T)T scala> bar(3) <console>:10: warning: The method bar would benefit from miniboxing type parameter T, since it is instantiated by a primitive type. bar(3) ^ res1: Int = 3
[T](t: T)T scala> def bar[@miniboxed T](t: T) = foo(t) <console>:8: warning: The method foo would benefit from miniboxing type parameter T, since it is instantiated by miniboxed type parameter T of method bar. def bar[@miniboxed T](t: T) = foo(t) ^ bar: [T](t: T)T
[T](t: T)T scala> def bar[@miniboxed T](t: T) = foo(t) <console>:8: warning: The method foo would benefit from miniboxing type parameter T, since it is instantiated by miniboxed type parameter T of method bar. def bar[@miniboxed T](t: T) = foo(t) ^ bar: [T](t: T)T scala> bar(3) res1: Int = 3
[T](t: T)T Why? Because the miniboxed bar should call miniboxed foo, but foo is not miniboxed... scala> def bar[@miniboxed T](t: T) = foo(t) <console>:8: warning: The method foo would benefit from miniboxing type parameter T, since it is instantiated by miniboxed type parameter T of method bar. def bar[@miniboxed T](t: T) = foo(t) ^ bar: [T](t: T)T scala> bar(3) res1: Int = 3
calling another • data uses miniboxing encoding – three patterns • initiator – starts an optimized trace • propagator – propagates it • inhibitor – goes back to boxed :(
calling another • data uses miniboxing encoding – three patterns • initiator – starts an optimized trace • propagator – propagates it • inhibitor – goes back to boxed :( Full tutorial on the website
the initial prototype, as a semester project • Eugene Burmako - the value class plugin based on the LDL transformation • Aymeric Genet - developing collection-like benchmarks for the miniboxing plugin • Martin Odersky, for his patient guidance • Eugene Burmako, for trusting the idea enough to develop the value-plugin based on the LDL transformation • Dmitry Petrashko, for the many cool discussions we had • Ilya Klyuchnikov and Pablo Guerrero - fixes and commits • Iulian Dragos, for his work on specialization and many explanations • Miguel Garcia, for his original insights that spawned the miniboxing idea • Michel Schinz, for his wonderful comments and enlightening ACC course • Andrew Myers and Roland Ducournau for the discussions we had and the feedback provided • Heather Miller for the eye-opening discussions we had • Vojin Jovanovic, Sandro Stucki, Manohar Jonalagedda and the whole LAMP laboratory in EPFL for the extraordinary atmosphere • Adriaan Moors, for the miniboxing name which stuck :)) • Thierry Coppey, Vera Salvisberg and George Nithin, who patiently listened to many presentations and provided valuable feedback • Grzegorz Kossakowski, for the many brainstorming sessions on specialization • Erik Osheim, Tom Switzer and Rex Kerr for their guidance on the Scala community side • OOPSLA paper and artifact reviewers, who reshaped the paper with their feedback • Sandro, Vojin, Nada, Heather, Manohar - reviews and discussions on the LDL paper • Hubert Plociniczak for the type notation in the LDL paper • Denys Shabalin, Dmitry Petrashko for their patient reviews of the LDL paper Special thanks to the Scala Community for their support! (@StuHood, @vpatryshev and everyone else!)
OOPSLA '13 Paper http://infoscience.epfl.ch/ record/188060 • OOPSLA Talk https://speakerdeck.com/vladureche/ late-data-layout-ooplsa-talk (or the Scala Bay talk) • OOPSLA '14 Paper http://infoscience.epfl.ch/ • record/200963 Code Transformation Related to value classes and multi-stage programming scala-ldl.org Clipart from www.clipartpanda.com
OOPSLA '13 Paper http://infoscience.epfl.ch/ record/188060 Other Considerations • Function Encoding (Bucharest FP) https://github.com/ miniboxing/miniboxing- plugin/blob/wip/docs/ 2014-08-miniboxing-bjug.pdf • The Quirks of Miniboxing (PDXScala) https://www.youtube.com/watch? v=g5yFlQySQ5k • OOPSLA Talk https://speakerdeck.com/vladureche/ late-data-layout-ooplsa-talk (or the Scala Bay talk) • OOPSLA '14 Paper http://infoscience.epfl.ch/ • record/200963 Code Transformation Related to value classes and multi-stage programming scala-ldl.org Clipart from www.clipartpanda.com
https://www.parleys.com/play/53a7d 2d0e4b0543940d9e567 • OOPSLA '13 Paper http://infoscience.epfl.ch/ record/188060 Other Considerations • Function Encoding (Bucharest FP) https://github.com/ miniboxing/miniboxing- plugin/blob/wip/docs/ 2014-08-miniboxing-bjug.pdf • The Quirks of Miniboxing (PDXScala) https://www.youtube.com/watch? v=g5yFlQySQ5k • OOPSLA Talk https://speakerdeck.com/vladureche/ late-data-layout-ooplsa-talk (or the Scala Bay talk) • OOPSLA '14 Paper http://infoscience.epfl.ch/ • record/200963 Code Transformation Related to value classes and multi-stage programming scala-ldl.org scala-miniboxing.org
support for distributed programming – Heather Miller, Philipp Haller + others https://github.com/scala/pickling https://github.com/heathermiller/spores