Showing posts with label lambda. Show all posts
Showing posts with label lambda. Show all posts

2013/11/13

Devoxx 2013 - Lambda: A Peek Under the Hood

Brian Goetz
lambda expression
  • "anonymous method"
  • type inference compiler
  • capture values from context
why lambdas for java
  • path to multicore support in libraries
  • library developers
  • competition other languages
  • inner classes: clunky
  • @runtime support
typing of lambda expressions
  • function types? -> VM / bytecode issues -> too complex
  • functional interfaces:
    • single method interfaces (cfr Runnable, Comparator)
    • compiler identifies functional interface
    • compiler infers lambda
      representation
  • inner classes? -> performance issues, error-prone, -> "obvious but wrong"
  • MethodHandle in Java7 (tool for compiler writers) -> performance issues, conflates binary representation with impl. -> wrong
  • invokedynamic
    • lets some language logic determine call logic
    • performant impl. in jvm
lambda & invokedynamic
  • code generation strategy (metafactory)
    • dynamic inner classes (=current Java 8 startegy)
    • wrapper class per interface
    • dynamic proxies (or MethodHandleProxy
  • vm-private APIs
    • build object from scratch
  • lazy evaluation
    • non-capturing lambda's: create single instance
    • defer initialization cost to first use
    • VM optimizes call
  • faster than inner classes
  • usable by other languages
  • serialization support: SerializeLambda
  • future VM optimizations
    • escape analysis

Devoxx 2013 Keynote: Java 8 and beyond

Mark Reinhold, Brian Goetz
Java: 18 years old
  • static language, but many dynamic features
  • many great features: gc, JIT ..
  • principles Java Language
    • reading code more important than writing
    • simplicity
    • one language, same everywhere
Java 8 features:
  • lambda expressions (+ type inference)
  • default methods in interfaces
  • java.util.stream: aggregate / data-parallel operations
lambda expressions:
  • inspiration: How to think about Parallel Programming -- Not (Guy Steele) (http://www.infoq.com/presentations/Thinking-Parallel-Programming)
  • more expressive code
    • instead of boilerplate of anonymous inner classes
    • syntax inspired from C#
    • single-method interfaces
    • ´´default´´ methods
      • default implementation
      • fully virtual
      • how stream() method was added
  • more powerful:
    • treat behavior as data
    • "gentle turn for the functional"
    • push away from mutative / imperative
    • huge impact on API design
  • more parallel
    • aggregate operations (filter, conversions, max, etc.)
    • stream() -> parallelStream() (single parallel pass on datasets)
    • retrofitted Collections
next:
  • value types: key enabler for
    • tuples,
    • user-defined primitive types