Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Data-centric Metaprogramming @ VMM 2015

Vlad Ureche
September 11, 2015

Data-centric Metaprogramming @ VMM 2015

The data-centric metaprogramming presentation at the VMM '15 (Virtual Machine Meetup), Zurich, Switzerland. Website: http://vmmeetup.github.io/2015/

Project website: http://scala-ildl.org

Vlad Ureche

September 11, 2015
Tweet

More Decks by Vlad Ureche

Other Decks in Programming

Transcript

  1. scala-ildl.org 11th of September 2015
    Virtual Machines Meetup
    Zürich, Switzerland
    Data-centric Metaprogramming

    View full-size slide

  2. scala-ildl.org
    STOP
    Please ask if things
    are not clear!

    View full-size slide

  3. scala-ildl.org
    Vlad URECHE
    PhD student in the Scala Team @ EPFL
    Working on program transformations
    focusing on data representation.
    Miniboxing guy. Scala compiler geek.
    @
    @VladUreche
    @VladUreche
    [email protected]

    View full-size slide

  4. scala-ildl.org
    Data-centric Metaprogramming

    View full-size slide

  5. scala-ildl.org
    Data-centric Metaprogramming
    Joint work with

    Martin Odersky

    Aggelos Biboudis

    Yannis Smaragdakis

    View full-size slide

  6. scala-ildl.org
    infoscience.epfl.ch/record/207050

    View full-size slide

  7. scala-ildl.org
    Motivation
    Transformation
    Applications
    Challenges
    Conclusion
    Related Work

    View full-size slide

  8. scala-ildl.org
    Data-centric Metaprogramming

    View full-size slide

  9. scala-ildl.org
    Data-centric Metaprogramming
    ... in Object-Oriented Languages

    View full-size slide

  10. scala-ildl.org
    Object Composition
    Object Composition
    class Vector[T] { … }

    View full-size slide

  11. scala-ildl.org
    Object Composition
    Object Composition
    class Vector[T] { … } The Vector collection
    in the Scala library

    View full-size slide

  12. scala-ildl.org
    Object Composition
    Object Composition
    class Employee(...)
    ID NAME SALARY
    class Vector[T] { … } The Vector collection
    in the Scala library

    View full-size slide

  13. scala-ildl.org
    Object Composition
    Object Composition
    class Employee(...)
    ID NAME SALARY
    Auto-generated,
    corresponds to a
    table row
    class Vector[T] { … } The Vector collection
    in the Scala library

    View full-size slide

  14. scala-ildl.org
    Object Composition
    Object Composition
    class Vector[T] { … }
    class Employee(...)
    ID NAME SALARY

    View full-size slide

  15. scala-ildl.org
    Object Composition
    Object Composition
    class Vector[T] { … }
    class Employee(...)
    ID NAME SALARY

    View full-size slide

  16. scala-ildl.org
    Object Composition
    Object Composition
    class Employee(...)
    ID NAME SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    class Vector[T] { … }

    View full-size slide

  17. scala-ildl.org
    Object Composition
    Object Composition
    class Employee(...)
    ID NAME SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    class Vector[T] { … }
    Traversal requires
    dereferencing a pointer
    for each employee.

    View full-size slide

  18. scala-ildl.org
    A Better Representation
    A Better Representation
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY

    View full-size slide

  19. scala-ildl.org
    A Better Representation
    A Better Representation
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY

    View full-size slide

  20. scala-ildl.org
    A Better Representation
    A Better Representation
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    iteration is 5x faster

    View full-size slide

  21. scala-ildl.org
    A Better Representation
    A Better Representation
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    iteration is 5x faster
    C++ would produce a
    better representation here,
    but there are still cases where
    the C++ representation could
    be improved over.

    View full-size slide

  22. scala-ildl.org
    A Better Representation
    A Better Representation

    In isolation Vector[T] and Employee are optimal

    View full-size slide

  23. scala-ildl.org
    A Better Representation
    A Better Representation

    In isolation Vector[T] and Employee are optimal

    Together, Vector[Employee] can be optimized

    View full-size slide

  24. scala-ildl.org
    A Better Representation
    A Better Representation

    In isolation Vector[T] and Employee are optimal

    Together, Vector[Employee] can be optimized
    Challenge: No means of
    communicating this
    to the compiler

    View full-size slide

  25. scala-ildl.org
    A Better Representation
    A Better Representation

    In isolation Vector[T] and Employee are optimal

    Together, Vector[Employee] can be optimized
    Challenge: No means of
    communicating this
    to the compiler
    You may disagree. We'll have
    a related work section later.

    View full-size slide

  26. scala-ildl.org

    View full-size slide

  27. scala-ildl.org

    Transforming the code by hand
    – Makes maintenance difficult
    – Changes are not contained

    View full-size slide

  28. scala-ildl.org

    Transforming the code by hand
    – Makes maintenance difficult
    – Changes are not contained
    Can we
    automate this?

    View full-size slide

  29. scala-ildl.org
    Motivation
    Transformation
    Applications
    Challenges
    Conclusion
    Related Work

    View full-size slide

  30. scala-ildl.org
    Transformation
    Transformation
    Definition Application

    View full-size slide

  31. scala-ildl.org
    Transformation
    Transformation
    Definition Application

    can't be automated

    based on experience

    based on speculation

    one-time effort

    View full-size slide

  32. scala-ildl.org
    Transformation
    Transformation
    Definition Application

    can't be automated

    based on experience

    based on speculation

    one-time effort
    programmer

    View full-size slide

  33. scala-ildl.org
    Transformation
    Transformation
    Definition Application

    can't be automated

    based on experience

    based on speculation

    one-time effort

    repetitive and simple

    affects code readability

    is verbose

    is error-prone
    programmer

    View full-size slide

  34. scala-ildl.org
    Transformation
    Transformation
    programmer
    Definition Application

    can't be automated

    based on experience

    based on speculation

    one-time effort

    repetitive and simple

    affects code readability

    is verbose

    is error-prone
    compiler
    (automated)

    View full-size slide

  35. scala-ildl.org
    Transformation
    Transformation
    programmer
    Definition Application

    can't be automated

    based on experience

    based on speculation

    one-time effort

    repetitive and simple

    affects code readability

    is verbose

    is error-prone
    compiler
    (automated)

    View full-size slide

  36. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    ...
    }

    View full-size slide

  37. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    ...
    }
    An object that
    describes a
    Transformation.

    View full-size slide

  38. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    ...
    }
    An object that
    describes a
    Transformation.
    A marker trait for
    transformations.

    View full-size slide

  39. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    ...
    }

    View full-size slide

  40. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    ...
    }
    What does the
    compiler need to
    know?

    View full-size slide

  41. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    ...
    }
    What does the
    compiler need to
    know?
    The target of the
    transformation and
    its representation.

    View full-size slide

  42. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    type Target = Vector[Employee]
    type Result = EmployeeVector
    ...
    }

    View full-size slide

  43. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    type Target = Vector[Employee]
    type Result = EmployeeVector
    ...
    } The transformation is
    type-driven we indicate

    the type of the target and
    of the representation.

    View full-size slide

  44. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    type Target = Vector[Employee]
    type Result = EmployeeVector
    ...
    } The transformation is
    type-driven we indicate

    the type of the target and
    of the representation.
    The improved representation
    is defined in the host language.

    View full-size slide

  45. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    type Target = Vector[Employee]
    type Result = EmployeeVector
    ...
    }

    View full-size slide

  46. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    type Target = Vector[Employee]
    type Result = EmployeeVector
    ...
    }
    How to transform
    Vector[Employee]
    into an
    EmployeeVector?

    View full-size slide

  47. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    type Target = Vector[Employee]
    type Result = EmployeeVector
    def toResult(t: Target): Result = ...
    def toTarget(t: Result): Target = ...
    ...
    }

    View full-size slide

  48. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    type Target = Vector[Employee]
    type Result = EmployeeVector
    def toResult(t: Target): Result = ...
    def toTarget(t: Result): Target = ...
    ...
    }
    Conversions to/from
    Vector[Employee]
    that consume/produce a
    EmployeeVector?

    View full-size slide

  49. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    type Target = Vector[Employee]
    type Result = EmployeeVector
    def toResult(t: Target): Result = ...
    def toTarget(t: Result): Target = ...
    ...
    }

    View full-size slide

  50. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    type Target = Vector[Employee]
    type Result = EmployeeVector
    def toResult(t: Target): Result = ...
    def toTarget(t: Result): Target = ...
    ...
    }
    So far so good, but how
    to execute Vector[Employee]
    operations on EmployeeVector?

    View full-size slide

  51. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    object VectorOfEmployeeOpt extends Transformation {
    type Target = Vector[Employee]
    type Result = EmployeeVector
    def toResult(t: Target): Result = ...
    def toTarget(t: Result): Target = ...
    def bypass_length: Int = ...
    def bypass_apply(i: Int): Employee = ...
    def bypass_update(i: Int, v: Employee) = ...
    def bypass_toString: String = ...
    ...
    }

    View full-size slide

  52. scala-ildl.org
    Data-centric Metaprogramming
    Data-centric Metaprogramming
    programmer
    Definition Application

    can't be automated

    based on experience

    based on speculation

    one-time effort

    repetitive and simple

    affects code readability

    is verbose

    is error-prone
    compiler
    (automated)

    View full-size slide

  53. scala-ildl.org
    Transformation
    Transformation
    programmer
    Definition Application

    can't be automated

    based on experience

    based on speculation

    one-time effort

    repetitive and simple

    affects code readability

    is verbose

    is error-prone
    compiler
    (automated)

    View full-size slide

  54. scala-ildl.org
    Transformation
    Transformation
    programmer
    Definition Application

    can't be automated

    based on experience

    based on speculation

    one-time effort

    repetitive and simple

    affects code readability

    is verbose

    is error-prone
    compiler
    (automated)
    In the paper

    View full-size slide

  55. scala-ildl.org
    Motivation
    Transformation
    Applications
    Challenges
    Conclusion
    Related Work

    View full-size slide

  56. scala-ildl.org
    Motivation
    Transformation
    Applications
    Challenges
    Conclusion
    Related Work
    Open-world
    Best Represenation?
    Composition

    View full-size slide

  57. scala-ildl.org
    Motivation
    Transformation
    Applications
    Challenges
    Conclusion
    Related Work
    Open-world
    Best Represenation?
    Composition

    View full-size slide

  58. scala-ildl.org
    Open World Assumption
    Open World Assumption
    class Vector[T] { … }
    class Employee(...)
    ID NAME SALARY

    View full-size slide

  59. scala-ildl.org
    Open World Assumption
    Open World Assumption
    class Vector[T] { … }
    class Employee(...)
    ID NAME SALARY

    View full-size slide

  60. scala-ildl.org
    Open World Assumption
    Open World Assumption
    class Employee(...)
    ID NAME SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    class Vector[T] { … }

    View full-size slide

  61. scala-ildl.org
    Open World Assumption
    Open World Assumption
    class Employee(...)
    ID NAME SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    class Vector[T] { … }
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY

    View full-size slide

  62. scala-ildl.org
    Open World Assumption
    Open World Assumption
    class Employee(...)
    ID NAME SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    class Vector[T] { … }
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY
    class NewEmployee(...)
    extends Employee(...)
    ID NAME SALARY DEPT

    View full-size slide

  63. scala-ildl.org
    Open World Assumption
    Open World Assumption
    class Employee(...)
    ID NAME SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    class Vector[T] { … }
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY
    class NewEmployee(...)
    extends Employee(...)
    ID NAME SALARY DEPT
    Oooops...

    View full-size slide

  64. scala-ildl.org
    Open World Assumption
    Open World Assumption

    Globally anything can happen

    View full-size slide

  65. scala-ildl.org
    Open World Assumption
    Open World Assumption

    Globally anything can happen

    Locally the programmer has full control:
    – Knows the values that will be used
    – Can reject non-conforming values

    View full-size slide

  66. scala-ildl.org
    Open World Assumption
    Open World Assumption

    Globally anything can happen

    Locally the programmer has full control:
    – Knows the values that will be used
    – Can reject non-conforming values How to
    use this
    information?

    View full-size slide

  67. scala-ildl.org
    Open World Assumption
    Open World Assumption

    Globally anything can happen

    Locally the programmer has full control:
    – Knows the values that will be used
    – Can reject non-conforming values How to
    use this
    information?
    Scopes

    View full-size slide

  68. scala-ildl.org
    Scopes
    Scopes
    def indexSalary(employees: Vector[Employee],
    by: Float): Vector[Employee] =
    for (employee ← employees)
    yield employee.copy(
    salary = (1 + by) * employee.salary
    )

    View full-size slide

  69. scala-ildl.org
    Scopes
    Scopes
    def indexSalary(employees: Vector[Employee],
    by: Float): Vector[Employee] =
    for (employee ← employees)
    yield employee.copy(
    salary = (1 + by) * employee.salary
    )
    Method operating on
    Scala collections
    (familiar to programmers)

    View full-size slide

  70. scala-ildl.org
    Scopes
    Scopes
    def indexSalary(employees: Vector[Employee],
    by: Float): Vector[Employee] =
    for (employee ← employees)
    yield employee.copy(
    salary = (1 + by) * employee.salary
    )

    View full-size slide

  71. scala-ildl.org
    Scopes
    Scopes
    transform(VectorOfEmployeeOpt) {
    def indexSalary(employees: Vector[Employee],
    by: Float): Vector[Employee] =
    for (employee ← employees)
    yield employee.copy(
    salary = (1 + by) * employee.salary
    )
    }

    View full-size slide

  72. scala-ildl.org
    Scopes
    Scopes
    transform(VectorOfEmployeeOpt) {
    def indexSalary(employees: Vector[Employee],
    by: Float): Vector[Employee] =
    for (employee ← employees)
    yield employee.copy(
    salary = (1 + by) * employee.salary
    )
    }
    Now the method operates
    on the EmployeeVector
    representation.

    View full-size slide

  73. scala-ildl.org
    Scopes
    Scopes
    transform(VectorOfEmployeeOpt) {
    def indexSalary(employees: Vector[Employee],
    by: Float): Vector[Employee] =
    for (employee ← employees)
    yield employee.copy(
    salary = (1 + by) * employee.salary
    )
    }
    Now the method operates
    on the EmployeeVector
    representation.
    Programmers can freely choose
    which parts of their code to transform.

    View full-size slide

  74. scala-ildl.org
    Scopes
    Scopes

    Can wrap statements, methods even entire classes
    – Inlined immediately after the parser
    – Definitions are visible outside the "scope"

    View full-size slide

  75. scala-ildl.org
    Scopes
    Scopes

    Can wrap statements, methods even entire classes
    – Inlined immediately after the parser
    – Definitions are visible outside the "scope"

    Locally closed world
    – Incoming/outgoing values go through conversions
    – Programmer can reject unexpected values

    View full-size slide

  76. scala-ildl.org
    Motivation
    Transformation
    Applications
    Challenges
    Conclusion
    Related Work
    Open-world
    Best Represenation?
    Composition

    View full-size slide

  77. scala-ildl.org
    Best Representation
    Best Representation
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY

    View full-size slide

  78. scala-ildl.org
    Best ...?
    Best ...?
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY

    View full-size slide

  79. scala-ildl.org
    Best ...?
    Best ...?
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    CompactVector

    View full-size slide

  80. scala-ildl.org
    Best ...?
    Best ...?
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    EmployeeJSON
    {
    id: 123,
    name: “John Doe”
    salary: 100
    }
    CompactVector

    View full-size slide

  81. scala-ildl.org
    Best ...?
    Best ...?
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    EmployeeJSON
    {
    id: 123,
    name: “John Doe”
    salary: 100
    }
    CompactVector

    Scopes!

    View full-size slide

  82. scala-ildl.org
    Scopes
    Scopes
    transform(VectorOfEmployeeOpt) {
    def indexSalary(employees: Vector[Employee],
    by: Float): Vector[Employee] =
    for (employee ← employees)
    yield employee.copy(
    salary = (1 + by) * employee.salary
    )
    }

    View full-size slide

  83. scala-ildl.org
    Scopes
    Scopes
    transform(VectorOfEmployeeOpt) {
    def indexSalary(employees: Vector[Employee],
    by: Float): Vector[Employee] =
    for (employee ← employees)
    yield employee.copy(
    salary = (1 + by) * employee.salary
    )
    }
    Method operating on
    column-based storage

    View full-size slide

  84. scala-ildl.org
    Scopes
    Scopes
    transform(VectorOfEmployeeBinary) {
    def indexSalary(employees: Vector[Employee],
    by: Float): Vector[Employee] =
    for (employee ← employees)
    yield employee.copy(
    salary = (1 + by) * employee.salary
    )
    }
    Method operating on
    binary data

    View full-size slide

  85. scala-ildl.org
    Scopes
    Scopes
    transform(VectorOfEmployeeJSON) {
    def indexSalary(employees: Vector[Employee],
    by: Float): Vector[Employee] =
    for (employee ← employees)
    yield employee.copy(
    salary = (1 + by) * employee.salary
    )
    }
    Method operating on
    JSON data

    View full-size slide

  86. scala-ildl.org
    Motivation
    Transformation
    Applications
    Challenges
    Conclusion
    Related Work
    Open-world
    Best Represenation?
    Composition

    View full-size slide

  87. scala-ildl.org
    Scope Composition
    Scope Composition

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations

    View full-size slide

  88. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations

    View full-size slide

  89. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations

    View full-size slide

  90. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations
    Coercions

    View full-size slide

  91. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations
    Coercions

    View full-size slide

  92. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations

    View full-size slide

  93. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations

    View full-size slide

  94. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations
    No coercions

    View full-size slide

  95. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations
    No coercions
    Even across
    separate compilation

    View full-size slide

  96. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations

    View full-size slide

  97. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations

    View full-size slide

  98. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations
    Two coercions
    Repr1 Target Repr2
    → →

    View full-size slide

  99. scala-ildl.org
    Scope Composition
    Scope Composition
    calling

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations

    View full-size slide

  100. scala-ildl.org
    Scope Composition
    Scope Composition
    calling
    overriding

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations

    View full-size slide

  101. scala-ildl.org
    Scope Composition
    Scope Composition
    calling
    overriding

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations
    The transformation has to
    preserve the object model.

    View full-size slide

  102. scala-ildl.org
    Scope Composition
    Scope Composition
    calling
    overriding

    Original code

    Transformed code

    Original code

    Transformed code

    Same transformation

    Different transformation

    Code can be
    – Left untransformed (using the original repr.)
    – Transformed using different representations
    The transformation has to
    preserve the object model.
    Handled automatically
    by the ildl transformation!

    View full-size slide

  103. scala-ildl.org
    Motivation
    Transformation
    Applications
    Challenges
    Conclusion
    Related Work
    Open-world
    Best Represenation?
    Composition

    View full-size slide

  104. scala-ildl.org
    Array of Stuct
    Array of Stuct (Column-oriented)
    (Column-oriented)
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY

    View full-size slide

  105. scala-ildl.org
    Array of Stuct
    Array of Stuct (Column-oriented)
    (Column-oriented)
    NAME ...
    NAME
    EmployeeVector
    ID ID ...
    ...
    SALARY SALARY
    Vector[Employee]
    ID NAME SALARY
    ID NAME SALARY
    5x faster

    View full-size slide

  106. scala-ildl.org
    Specialization
    Specialization and stack allocation
    and stack allocation
    3 5
    (3,5)
    Tuples in Scala
    are generic so
    they need to use
    pointers and objects

    View full-size slide

  107. scala-ildl.org
    Specialization
    Specialization and stack allocation
    and stack allocation
    3 5
    3 5
    (3,5) (3,5)
    Tuples in Scala
    are generic so
    they need to use
    pointers and objects
    + stack
    allocation

    View full-size slide

  108. scala-ildl.org
    + stack
    allocation
    Specialization
    Specialization and stack allocation
    and stack allocation
    14x faster
    reduced memory footprint
    3 5
    3 5
    (3,5) (3,5)
    Tuples in Scala
    are generic so
    they need to use
    pointers and objects

    View full-size slide

  109. scala-ildl.org
    Deforestation
    Deforestation
    List(1,2,3).map(_ + 1).map(_ * 2).sum

    View full-size slide

  110. scala-ildl.org
    Deforestation
    Deforestation
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    List(2,3,4)

    View full-size slide

  111. scala-ildl.org
    Deforestation
    Deforestation
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    List(2,3,4) List(4,6,8)

    View full-size slide

  112. scala-ildl.org
    Deforestation
    Deforestation
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    List(2,3,4) List(4,6,8) 18

    View full-size slide

  113. scala-ildl.org
    Deforestation
    Deforestation
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    List(2,3,4) List(4,6,8) 18

    View full-size slide

  114. scala-ildl.org
    Deforestation
    Deforestation
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    List(2,3,4) List(4,6,8) 18
    transform(ListDeforestation) {
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    }

    View full-size slide

  115. scala-ildl.org
    Deforestation
    Deforestation
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    List(2,3,4) List(4,6,8) 18
    transform(ListDeforestation) {
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    }
    accumulate
    function

    View full-size slide

  116. scala-ildl.org
    Deforestation
    Deforestation
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    List(2,3,4) List(4,6,8) 18
    transform(ListDeforestation) {
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    }
    accumulate
    function
    accumulate
    function

    View full-size slide

  117. scala-ildl.org
    Deforestation
    Deforestation
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    List(2,3,4) List(4,6,8) 18
    transform(ListDeforestation) {
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    }
    accumulate
    function
    accumulate
    function
    compute:
    18

    View full-size slide

  118. scala-ildl.org
    Deforestation
    Deforestation
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    List(2,3,4) List(4,6,8) 18
    transform(ListDeforestation) {
    List(1,2,3).map(_ + 1).map(_ * 2).sum
    }
    accumulate
    function
    accumulate
    function
    compute:
    18
    6x faster

    View full-size slide

  119. scala-ildl.org
    Motivation
    Transformation
    Applications
    Challenges
    Conclusion
    Related Work
    Open-world
    Best Represenation?
    Composition

    View full-size slide

  120. scala-ildl.org
    Multi-Stage Programming
    Multi-Stage Programming

    Multi-Stage Programming
    – “Abstraction without regret” - Tiark Rompf
    – DSLs small enough to be staged


    10000x speed improvements

    View full-size slide

  121. scala-ildl.org
    Multi-Stage Programming
    Multi-Stage Programming

    Multi-Stage Programming
    – “Abstraction without regret” - Tiark Rompf
    – DSLs small enough to be staged


    10000x speed improvements
    – Scala many features not supported by LMS:


    Separate compilation/modularization

    Dynamic dispatch

    Aliasing

    Reflection

    View full-size slide

  122. scala-ildl.org
    Multi-Stage Programming
    Multi-Stage Programming

    Multi-Stage Programming
    – “Abstraction without regret” - Tiark Rompf
    – DSLs small enough to be staged


    10000x speed improvements
    – Scala many features not supported by LMS:


    Separate compilation/modularization

    Dynamic dispatch

    Aliasing

    Reflection
    If we add support,
    we lose the ability
    to optimize code :(

    View full-size slide

  123. scala-ildl.org
    Low-level Optimizers
    Low-level Optimizers

    JIT optimizers with virtual machine support
    – Access to the low-level code
    – Can assume a (local) closed world
    – Can speculate based on profiles
    – On the critical path – limited analysis

    View full-size slide

  124. scala-ildl.org
    Low-level Optimizers
    Low-level Optimizers

    JIT optimizers with virtual machine support
    – Access to the low-level code
    – Can assume a (local) closed world
    – Can speculate based on profiles
    – On the critical path – limited analysis
    – Biggest opportunities are high-level - O(n2) O(n)


    Incoming code is low-level

    Rarely possible to recover opportunities

    View full-size slide

  125. scala-ildl.org
    Low-level Optimizers
    Low-level Optimizers

    JIT optimizers with virtual machine support
    – Access to the low-level code
    – Can assume a (local) closed world
    – Can speculate based on profiles
    – On the critical path – limited analysis
    – Biggest opportunities are high-level - O(n2) O(n)


    Incoming code is low-level

    Rarely possible to recover opportunities
    Typical solution:
    Metaprogramming

    View full-size slide

  126. scala-ildl.org
    Metaprogramming
    Metaprogramming

    Not your grandpa's C preprocessor
    def optimize(tree: AST): AST = {
    ...
    }

    View full-size slide

  127. scala-ildl.org
    Metaprogramming
    Metaprogramming

    Not your grandpa's C preprocessor

    Full-fledged program transformers
    – :) Lots of power
    def optimize(tree: AST): AST = {
    ...
    }

    View full-size slide

  128. scala-ildl.org
    Metaprogramming
    Metaprogramming

    Not your grandpa's C preprocessor

    Full-fledged program transformers
    – :) Lots of power
    – :( Lots of responsibility
    def optimize(tree: AST): AST = {
    ...
    }

    View full-size slide

  129. scala-ildl.org
    Metaprogramming
    Metaprogramming

    Not your grandpa's C preprocessor

    Full-fledged program transformers
    – :) Lots of power
    – :( Lots of responsibility

    Compiler invariants

    Object-oriented model

    Modularity
    def optimize(tree: AST): AST = {
    ...
    }

    View full-size slide

  130. scala-ildl.org
    Metaprogramming
    Metaprogramming

    Not your grandpa's C preprocessor

    Full-fledged program transformers
    – :) Lots of power
    – :( Lots of responsibility

    Compiler invariants

    Object-oriented model

    Modularity
    def optimize(tree: AST): AST = {
    ...
    }
    Can we make
    metaprogramming
    “high-level”?

    View full-size slide

  131. scala-ildl.org
    Motivation
    Transformation
    Applications
    Challenges
    Conclusion
    Related Work
    Open-world
    Best Represenation?
    Composition

    View full-size slide

  132. scala-ildl.org
    Conclusion
    Conclusion

    Object-oriented composition inefcient representation


    Solution: data-centric metaprogramming
    – Splitting the responsibility:

    Defining the Transformation programmer


    Applying the Transformation compiler

    – Scopes

    Adapt the data representation to the operation

    Allow speculating properties of the scope

    We've just begun to scratch the surface
    – Many interesting research questions lie ahead

    View full-size slide

  133. scala-ildl.org
    Conclusion
    Conclusion

    Object-oriented composition inefcient representation


    Solution: data-centric metaprogramming
    – Splitting the responsibility:

    Defining the Transformation programmer


    Applying the Transformation compiler

    – Scopes

    Adapt the data representation to the operation

    Allow speculating properties of the scope

    We've just begun to scratch the surface
    – Many interesting research questions lie ahead

    View full-size slide

  134. scala-ildl.org
    Conclusion
    Conclusion

    Object-oriented composition inefcient representation


    Solution: data-centric metaprogramming
    – Splitting the responsibility:

    Defining the Transformation programmer


    Applying the Transformation compiler

    – Scopes

    Adapt the data representation to the operation

    Allow speculating properties of the scope

    We've just begun to scratch the surface
    – Many interesting research questions lie ahead

    View full-size slide

  135. scala-ildl.org
    Conclusion
    Conclusion

    Object-oriented composition inefcient representation


    Solution: data-centric metaprogramming
    – Splitting the responsibility:

    Defining the Transformation programmer


    Applying the Transformation compiler

    – Scopes

    Adapt the data representation to the operation

    Allow speculating properties of the scope

    We've just begun to scratch the surface
    – Many interesting research questions lie ahead

    View full-size slide

  136. scala-ildl.org
    infoscience.epfl.ch/record/207050

    View full-size slide

  137. scala-ildl.org
    github.com/miniboxing/ildl-plugin

    View full-size slide

  138. scala-ildl.org
    github.com/miniboxing/ildl-plugin

    View full-size slide

  139. scala-ildl.org
    github.com/miniboxing/ildl-plugin
    Examples of data-centric metaprogramming applications

    View full-size slide

  140. scala-ildl.org

    View full-size slide

  141. scala-ildl.org
    Thank you!

    View full-size slide