Slide 1

Slide 1 text

scala-ldl.org Late Data Layout: Unifying Data Representation Transformations Vlad Ureche Eugene Burmako Martin Odersky École polytechnique fédérale de Lausanne, Switzerland {first.last}@epfl.ch 23rd of October 2014 OOPSLA '14 Portland, OR

Slide 2

Slide 2 text

scala-ldl.org Late Data Layout: Unifying Data Representation Transformations

Slide 3

Slide 3 text

scala-ldl.org Late Data Layout: Unifying Data Representation Transformations ● compiler transformations ● separate compilation ● global scope

Slide 4

Slide 4 text

scala-ldl.org Late Data Layout: Unifying Data Representation Transformations ● unboxing, value classes ● how data is represented

Slide 5

Slide 5 text

scala-ldl.org Late Data Layout: Unifying Data Representation Transformations ● what is there to unify? ● why bother?

Slide 6

Slide 6 text

scala-ldl.org Motivation Transformation Conclusion Properties Benchmarks

Slide 7

Slide 7 text

scala-ldl.org Representation Transformations

Slide 8

Slide 8 text

scala-ldl.org Unboxing Primitive Types Representation Transformations

Slide 9

Slide 9 text

scala-ldl.org Unboxing Primitive Types Unboxing Primitive Types

Slide 10

Slide 10 text

scala-ldl.org Unboxing Primitive Types Unboxing Primitive Types int ● value ● no garbage collection ● locality

Slide 11

Slide 11 text

scala-ldl.org Unboxing Primitive Types Unboxing Primitive Types ● indirect access ● object allocation ● and thus garbage collection ● no locality guarantees ● compatible with erased generics java.lang.Integer int ● value ● no garbage collection ● locality

Slide 12

Slide 12 text

scala-ldl.org Unboxing Primitive Types Unboxing Primitive Types ● indirect access ● object allocation ● and thus garbage collection ● no locality guarantees ● compatible with erased generics java.lang.Integer in Java, programmers are responsible for the choice of representation int ● value ● no garbage collection ● locality

Slide 13

Slide 13 text

scala-ldl.org Unboxing Primitive Types Unboxing Primitive Types ● indirect access ● object allocation ● and thus garbage collection ● no locality guarantees ● compatible with erased generics java.lang.Integer in Java, programmers are responsible for the choice of representation What about Scala? int ● value ● no garbage collection ● locality

Slide 14

Slide 14 text

scala-ldl.org Unboxing Primitive Types Unboxing Primitive Types ● indirect access ● object allocation ● and thus garbage collection ● no locality guarantees ● compatible with erased generics java.lang.Integer int ● value ● no garbage collection ● locality

Slide 15

Slide 15 text

scala-ldl.org Unboxing Primitive Types Unboxing Primitive Types ● indirect access ● object allocation ● and thus garbage collection ● no locality guarantees ● compatible with erased generics java.lang.Integer int ● value ● no garbage collection ● locality

Slide 16

Slide 16 text

scala-ldl.org Unboxing Primitive Types Unboxing Primitive Types ● indirect access ● object allocation ● and thus garbage collection ● no locality guarantees ● compatible with erased generics java.lang.Integer int ● value ● no garbage collection ● locality scala.Int

Slide 17

Slide 17 text

scala-ldl.org Unboxing Primitive Types Unboxing Primitive Types ● indirect access ● object allocation ● and thus garbage collection ● no locality guarantees ● compatible with erased generics java.lang.Integer int ● value ● no garbage collection ● locality scalac scala.Int

Slide 18

Slide 18 text

scala-ldl.org Unboxing Primitive Types Unboxing Primitive Types ● indirect access ● object allocation ● and thus garbage collection ● no locality guarantees ● compatible with erased generics java.lang.Integer int ● value ● no garbage collection ● locality scalac Choice of representation 1 scala.Int

Slide 19

Slide 19 text

scala-ldl.org Unboxing Primitive Types Unboxing Primitive Types ● indirect access ● object allocation ● and thus garbage collection ● no locality guarantees ● compatible with erased generics java.lang.Integer int ● value ● no garbage collection ● locality scalac Choice of representation 1 2 Coercions between representations scala.Int

Slide 20

Slide 20 text

scala-ldl.org Unboxing Primitive Types Value Classes Representation Transformations

Slide 21

Slide 21 text

scala-ldl.org Value Classes Value Classes

Slide 22

Slide 22 text

scala-ldl.org Value Classes Value Classes value class

Slide 23

Slide 23 text

scala-ldl.org Value Classes Value Classes value class struct (by-val) ● preferred encoding ● fields are inlined ● no heap allocations

Slide 24

Slide 24 text

scala-ldl.org Value Classes Value Classes value class struct (by-val) ● preferred encoding ● fields are inlined ● no heap allocations ● fallback encoding ● compatible with ● subtyping ● erased generics object (by-ref)

Slide 25

Slide 25 text

scala-ldl.org Value Classes Value Classes value class struct (by-val) ● preferred encoding ● fields are inlined ● no heap allocations ● fallback encoding ● compatible with ● subtyping ● erased generics object (by-ref) scalac Choice of representation 1 2 Coercions between representations

Slide 26

Slide 26 text

scala-ldl.org Unboxing Primitive Types Value Classes Miniboxing Representation Transformations

Slide 27

Slide 27 text

scala-ldl.org Miniboxing Miniboxing OOPSLA '13

Slide 28

Slide 28 text

scala-ldl.org Miniboxing Miniboxing T (primitive)

Slide 29

Slide 29 text

scala-ldl.org Miniboxing Miniboxing long integer ● preferred encoding ● for all primitive types T (primitive)

Slide 30

Slide 30 text

scala-ldl.org Miniboxing Miniboxing long integer ● preferred encoding ● for all primitive types ● fallback encoding ● compatible with ● virtual dispatch ● subtyping ● erased generics T (erased to Object) T (primitive)

Slide 31

Slide 31 text

scala-ldl.org Miniboxing Miniboxing long integer ● preferred encoding ● for all primitive types ● fallback encoding ● compatible with ● virtual dispatch ● subtyping ● erased generics T (erased to Object) T (primitive) scalac Choice of representation 1 2 Coercions between representations

Slide 32

Slide 32 text

scala-ldl.org Unboxing Primitive Types Value Classes Representation Transformations Miniboxing

Slide 33

Slide 33 text

scala-ldl.org Unboxing Primitive Types Value Classes Representation Transformations Miniboxing motivated by erased generics

Slide 34

Slide 34 text

scala-ldl.org Unboxing Primitive Types Value Classes Representation Transformations Miniboxing motivated by erased generics Staging (Multi-Stage Programming)

Slide 35

Slide 35 text

scala-ldl.org Staging Staging Program Result 1+1+3 5 1-stage execution

Slide 36

Slide 36 text

scala-ldl.org Staging Staging Program Result 1+1+3 5 1-stage execution Program Program Result 2+3 1+1+3 5 2-stage execution

Slide 37

Slide 37 text

scala-ldl.org Staging Staging value

Slide 38

Slide 38 text

scala-ldl.org Staging Staging value direct value (5) ● is a computed value ● from an expression evaluated in the current stage

Slide 39

Slide 39 text

scala-ldl.org Staging Staging value direct value (5) ● is a computed value ● from an expression evaluated in the current stage ● executed in the next stage ● stores the expression that produces the value lifted expression (2+3)

Slide 40

Slide 40 text

scala-ldl.org scalac Staging Staging value direct value (5) ● is a computed value ● from an expression evaluated in the current stage ● executed in the next stage ● stores the expression that produces the value lifted expression (2+3) Choice of representation – domain-specific 1 2 Coercions between representations

Slide 41

Slide 41 text

scala-ldl.org Motivation Transformation Conclusion Properties Benchmarks

Slide 42

Slide 42 text

scala-ldl.org How to transform a program?

Slide 43

Slide 43 text

scala-ldl.org How to transform a program? We'll use primitive unboxing as the running example, to keep things simple

Slide 44

Slide 44 text

scala-ldl.org Syntax-based transformation Late Data Layout transformation

Slide 45

Slide 45 text

scala-ldl.org Syntax-based transformation Late Data Layout transformation

Slide 46

Slide 46 text

scala-ldl.org Syntax-based Syntax-based ● we need coercions between representations ● simple set of syntax-based rules – example

Slide 47

Slide 47 text

scala-ldl.org Syntax-based Syntax-based val x: Int = ... val y: Int = x

Slide 48

Slide 48 text

scala-ldl.org Syntax-based Syntax-based val x: Int = ... val y: Int = x

Slide 49

Slide 49 text

scala-ldl.org Syntax-based Syntax-based val x: Int = ... val y: Int = x val x: int = unbox(...) val y: Int = box(x)

Slide 50

Slide 50 text

scala-ldl.org Syntax-based Syntax-based val x: Int = ... val y: Int = x val x: int = unbox(...) val y: Int = box(x) Coerce the definition right-hand side

Slide 51

Slide 51 text

scala-ldl.org Syntax-based Syntax-based val x: Int = ... val y: Int = x val x: int = unbox(...) val y: Int = box(x) Coerce all occurences of the transformed value

Slide 52

Slide 52 text

scala-ldl.org Syntax-based Syntax-based val x: Int = ... val y: Int = x val x: int = unbox(...) val y: Int = box(x)

Slide 53

Slide 53 text

scala-ldl.org Syntax-based Syntax-based val x: Int = ... val y: Int = x val x: int = unbox(...) val y: Int = box(x) val x: int = unbox(...) val y: int = unbox(box(x))

Slide 54

Slide 54 text

scala-ldl.org Syntax-based Syntax-based val x: Int = ... val y: Int = x val x: int = unbox(...) val y: Int = box(x) val x: int = unbox(...) val y: int = unbox(box(x)) suboptimal

Slide 55

Slide 55 text

scala-ldl.org Peephole Optimization Peephole Optimization val y: int = unbox(box(x)) val y: int = x peephole

Slide 56

Slide 56 text

scala-ldl.org Syntax-based Syntax-based another example

Slide 57

Slide 57 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: Int, t2: Int): Int = if (Random.nextBoolean()) t1 else t2

Slide 58

Slide 58 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: Int, t2: Int): Int = if (Random.nextBoolean()) t1 else t2 Transform one by one

Slide 59

Slide 59 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: Int): Int = if (Random.nextBoolean()) box(t1) else t2

Slide 60

Slide 60 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): Int = if (Random.nextBoolean()) box(t1) else box(t2)

Slide 61

Slide 61 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): Int = if (Random.nextBoolean()) box(t1) else box(t2) Anything missing?

Slide 62

Slide 62 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): Int = if (Random.nextBoolean()) box(t1) else box(t2) Anything missing? Yes, unboxing the returned value

Slide 63

Slide 63 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): Int = if (Random.nextBoolean()) box(t1) else box(t2)

Slide 64

Slide 64 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): Int = if (Random.nextBoolean()) box(t1) else box(t2)

Slide 65

Slide 65 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): int = if (Random.nextBoolean()) box(t1) else box(t2)

Slide 66

Slide 66 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): int = unbox( if (Random.nextBoolean()) box(t1) else box(t2) )

Slide 67

Slide 67 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): int = unbox( if (Random.nextBoolean()) box(t1) else box(t2) )

Slide 68

Slide 68 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): int = unbox( if (Random.nextBoolean()) box(t1) else box(t2) )

Slide 69

Slide 69 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): int = unbox( if (Random.nextBoolean()) box(t1) else box(t2) ) new peephole rule

Slide 70

Slide 70 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): int = unbox( if (Random.nextBoolean()) box(t1) else box(t2) ) new peephole rule sink outside coercions into the if branches

Slide 71

Slide 71 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): int = if (Random.nextBoolean()) unbox(box(t1)) else unbox(box(t2))

Slide 72

Slide 72 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): int = if (Random.nextBoolean()) unbox(box(t1)) else unbox(box(t2))

Slide 73

Slide 73 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): int = if (Random.nextBoolean()) t1 else t2

Slide 74

Slide 74 text

scala-ldl.org Syntax-based Syntax-based def choice(t1: int, t2: int): int = if (Random.nextBoolean()) t1 else t2 complicated

Slide 75

Slide 75 text

scala-ldl.org Syntax-based Syntax-based ● peephole transformation does not scale – needs multiple rewrite rules for each node – needs stateful rewrite rules – leads to an explosion of rules x states Details in the paper

Slide 76

Slide 76 text

scala-ldl.org Coercions are fixed in the tree

Slide 77

Slide 77 text

scala-ldl.org Coercions are fixed in the tree and moving them around is difficult.

Slide 78

Slide 78 text

scala-ldl.org Coercions are fixed in the tree and moving them around is difficult. We need a more fluid abstraction.

Slide 79

Slide 79 text

scala-ldl.org Coercions are fixed in the tree and moving them around is difficult. We need a more fluid abstraction. Types

Slide 80

Slide 80 text

scala-ldl.org Syntax-based transformation Late Data Layout transformation

Slide 81

Slide 81 text

scala-ldl.org Inject Coerce Commit Phases Late Data Layout transformation

Slide 82

Slide 82 text

scala-ldl.org LDL Transformation LDL Transformation ● propagates representation information – into the type system ● based on annotated types ● e.g. an @unboxed annotation added to integers The Inject Phase The Inject Phase

Slide 83

Slide 83 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: Int, t2: Int): Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit

Slide 84

Slide 84 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit

Slide 85

Slide 85 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit depending on the transformation, other operations can be performed as well (e.g. miniboxing duplicates methods)

Slide 86

Slide 86 text

scala-ldl.org Inject Coerce Commit Phases Late Data Layout transformation

Slide 87

Slide 87 text

scala-ldl.org LDL Transformation LDL Transformation ● introduces coercions – re-type-checks the tree – exposes representation mismatches ● as annotation mismatches (Int vs @unboxed Int) ● leading to coercions The Coerce Phase The Coerce Phase

Slide 88

Slide 88 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit

Slide 89

Slide 89 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit

Slide 90

Slide 90 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit the return type of choice is @unboxed Int

Slide 91

Slide 91 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit the return type of choice is @unboxed Int

Slide 92

Slide 92 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : @unboxed Int the return type of choice is @unboxed Int

Slide 93

Slide 93 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : @unboxed Int expected type (part of local type inference) the return type of choice is @unboxed Int

Slide 94

Slide 94 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : @unboxed Int

Slide 95

Slide 95 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : Boolean

Slide 96

Slide 96 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : Boolean matches: expected: Boolean found: Boolean

Slide 97

Slide 97 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : @unboxed Int

Slide 98

Slide 98 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : @unboxed Int matches: expected: @unboxed Int found: @unboxed Int

Slide 99

Slide 99 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : @unboxed Int

Slide 100

Slide 100 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit matches: ... : @unboxed Int

Slide 101

Slide 101 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit

Slide 102

Slide 102 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit LDL optimally transforms the tree the first time

Slide 103

Slide 103 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit LDL optimally transforms the tree the first time No peephole transformation

Slide 104

Slide 104 text

scala-ldl.org Inject Coerce Commit Phases Late Data Layout transformation

Slide 105

Slide 105 text

scala-ldl.org LDL Transformation LDL Transformation ● converts annotations to representations – @unboxed Int → int – Int java.lang.Integer → ● coercion markers are also transformed – box(...) → new Integer(...) – unbox(...) → ....intValue The Commit Phase The Commit Phase

Slide 106

Slide 106 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: @unboxed Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit

Slide 107

Slide 107 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: int, t2: int): int = if (Random.nextBoolean()) t1 else t2 inject coerce commit

Slide 108

Slide 108 text

scala-ldl.org LDL Transformation LDL Transformation def choice(t1: int, t2: int): int = if (Random.nextBoolean()) t1 else t2 inject coerce commit that's it!

Slide 109

Slide 109 text

scala-ldl.org Inject Coerce Commit Phases Late Data Layout transformation

Slide 110

Slide 110 text

scala-ldl.org Motivation Transformation Conclusion Properties Benchmarks

Slide 111

Slide 111 text

scala-ldl.org Selectivity Consistency Optimality (not formally proven yet) Properties Late Data Layout transformation

Slide 112

Slide 112 text

scala-ldl.org Selectivity Selectivity inject coerce commit ● annotated types – selectively pick the representation for each value

Slide 113

Slide 113 text

scala-ldl.org Selectivity Selectivity inject coerce commit ● annotated types – selectively pick the representation for each value ● selectivity is used for – bridge methods (some args boxed, others unboxed) – value classes (JVM: no multi-value returns) – staging (representation: domain-specific knowledge) ● List[Int] vs List[@staged Int] vs @staged List[Int]

Slide 114

Slide 114 text

scala-ldl.org Selectivity Selectivity def choice(t1: Int, t2: Int): Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit

Slide 115

Slide 115 text

scala-ldl.org Selectivity Selectivity def choice(t1: Int, t2: Int): Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit what if we did not annotate t1?

Slide 116

Slide 116 text

scala-ldl.org Selectivity Selectivity def choice(t1: Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit what if we did not annotate t1?

Slide 117

Slide 117 text

scala-ldl.org Selectivity Selectivity def choice(t1: Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : @unboxed Int

Slide 118

Slide 118 text

scala-ldl.org Selectivity Selectivity def choice(t1: Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : @unboxed Int

Slide 119

Slide 119 text

scala-ldl.org Selectivity Selectivity def choice(t1: Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : @unboxed Int mismatch: expected: @unboxed Int found: Int

Slide 120

Slide 120 text

scala-ldl.org Selectivity Selectivity def choice(t1: Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) t1 else t2 inject coerce commit : @unboxed Int mismatch: expected: @unboxed Int found: Int coercion

Slide 121

Slide 121 text

scala-ldl.org Selectivity Selectivity def choice(t1: Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) unbox(t1) else t2 inject coerce commit

Slide 122

Slide 122 text

scala-ldl.org Selectivity Selectivity def choice(t1: Int, t2: @unboxed Int): @unboxed Int = if (Random.nextBoolean()) unbox(t1) else t2 inject coerce commit

Slide 123

Slide 123 text

scala-ldl.org Selectivity Selectivity def choice(t1: java.lang.Integer, t2: int): int = if (Random.nextBoolean()) t1.intValue else t2 inject coerce commit

Slide 124

Slide 124 text

scala-ldl.org Selectivity Consistency Optimality (not formally proven yet) Properties Late Data Layout transformation

Slide 125

Slide 125 text

scala-ldl.org Consistency Consistency inject coerce commit ● representations become part of types ● re-type-checking the program – proves type correctness – proves representation consistency

Slide 126

Slide 126 text

scala-ldl.org Selectivity Consistency Optimality (not formally proven yet) Properties Late Data Layout transformation

Slide 127

Slide 127 text

scala-ldl.org Optimality Optimality def choice(t1: java.lang.Integer, t2: int): int = if (Random.nextBoolean()) t1.intValue else t2 inject coerce commit

Slide 128

Slide 128 text

scala-ldl.org Optimality Optimality def choice(t1: java.lang.Integer, t2: int): int = if (Random.nextBoolean()) t1.intValue else t2 execution inject coerce commit

Slide 129

Slide 129 text

scala-ldl.org Optimality Optimality def choice(t1: java.lang.Integer, t2: int): int = if (Random.nextBoolean()) t1.intValue else t2 1 coercion execution inject coerce commit

Slide 130

Slide 130 text

scala-ldl.org Optimality Optimality def choice(t1: java.lang.Integer, t2: int): int = if (Random.nextBoolean()) t1.intValue else t2 1 coercion no coercions execution inject coerce commit

Slide 131

Slide 131 text

scala-ldl.org Optimality Optimality ● on any execution trace through the program – the number of coercions executed is minimum – assuming the program terminates inject coerce commit

Slide 132

Slide 132 text

scala-ldl.org Optimality Optimality ● on any execution trace through the program – the number of coercions executed is minimum – assuming the program terminates ● modulo – annotations introduced by the inject phase ● unbox both parameters → no coercions at all inject coerce commit

Slide 133

Slide 133 text

scala-ldl.org Optimality Optimality ● on any execution trace through the program – the number of coercions executed is minimum – assuming the program terminates ● modulo – annotations introduced by the inject phase ● unbox both parameters → no coercions at all – post-transformations done by the commit phase ● box(...) → new Integer(new Integer(...).intValue) inject coerce commit

Slide 134

Slide 134 text

scala-ldl.org Optimality Optimality ● peephole optimization – propagates coercions ● type system – propagates types inject coerce commit

Slide 135

Slide 135 text

scala-ldl.org Optimality Optimality ● peephole optimization – propagates coercions ● type system – propagates types – but types are fluid whereas coercions are not details in the paper inject coerce commit

Slide 136

Slide 136 text

scala-ldl.org Selectivity Consistency Optimality (not formally proven yet) Properties Late Data Layout transformation

Slide 137

Slide 137 text

scala-ldl.org Motivation Transformation Conclusion Properties Benchmarks

Slide 138

Slide 138 text

scala-ldl.org LDL is used in LDL is used in ● Scala compiler plugins – miniboxing (specialization) – value-class plugin – staging plugin

Slide 139

Slide 139 text

scala-ldl.org Benchmarks Benchmarks … … in the paper in the paper ● implementation effort – Late Data Layout mechanism ● developed as part of miniboxing ● reused by the other compiler plugins – value class plugin → 2 developer-weeks – staging plugin → 1 developer-week

Slide 140

Slide 140 text

scala-ldl.org Benchmarks Benchmarks … … in the paper in the paper ● performance – baseline vs transformed code ● numbers – up to 2x speedup when transforming value classes – up to 22x speedup when using miniboxing – up to 59x speedup when staging

Slide 141

Slide 141 text

scala-ldl.org Motivation Transformation Conclusion Properties Benchmarks

Slide 142

Slide 142 text

scala-ldl.org Conclusion Conclusion Insights Insights ● use annotated types – to selectively mark values with the representation ● use expected type propagation – to provide optimal transformation ● use the type system – to provide representation consistency

Slide 143

Slide 143 text

scala-ldl.org Credits and Thank you-s ● Cristian Talau - developed 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 ● 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 ● Xiaoya Xiang and Philip Stutz for trusting miniboxing enough to try it out Special thanks to the Scala Community for their support! (@StuHood, @vpatryshev and everyone else!)

Slide 144

Slide 144 text

scala-ldl.org concept repr. 1 … repr. n repr. 2

Slide 145

Slide 145 text

scala-ldl.org concept repr. 1 … repr. n repr. 2 How would you use this?

Slide 146

Slide 146 text

scala-ldl.org Thank you! concept repr. 1 … repr. n repr. 2 How would you use this?