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

Know Your Runtime

Know Your Runtime

My talk at devfest.cz held in Prague, 2013. In this talk I try to explain why clean code isn't slow and I explain what your runtime system does to make your clean code fast.

Avatar for Marcel Hlopko

Marcel Hlopko

November 23, 2013

Other Decks in Programming

Transcript

  1. . .

  2. Is %s slow? ▶ allocating many new objects ▶ calling

    virtual methods ▶ having many small methods ▶ throwing exceptions ▶ creating threads
  3. Java Performance Tuning You should look at the object and

    consider whether it is possible to reset the fields and then reuse the object, rather than throw it away and create another.
  4. . .

  5. Mark & Sweep 1. stop the world 2. walk the

    heap 3. find garbage 4. collect it
  6. Baker's algorithm ✓ garbage is for free!! ✓ one pass

    over heap ✓ no fragmentation × stops the world × memory demanding
  7. Generational GC Most objects die young ▶ small eden with

    baker ▶ big oldgen with incremental mark & sweep
  8. Caching vs. naive ▶ Baker in eden - fast allocation,

    trash for free ▶ M&S in oldgen - need to remember and update pointers
  9. Just-In-Time Interpreted code simple native code optimized native code when

    called few times when hot when wrong when wrong
  10. JIT Inlines ▶ final methods ▶ static methods ▶ unique

    methods ▶ virtual methods *if it wants to
  11. JIT Inlines If your small methods are called often enough,

    they will be inlined and there will be no overhead.
  12. if check public void hello(String name) { if (name ==

    null) { return; } sayHelloTo(name); }
  13. throw/catch public void hello(String name) { try { sayHelloTo(name); }

    catch (NullPointerException e) { return; } }
  14. OS Threads vs. Green Threads OS Thread OS Thread JVM

    Scheduler Green Thread Green Thread Green Thread Green Thread
  15. . .

  16. . .

  17. Marcel Hlopko ▶ developing awesome Rails apps by day and

    hacking and breaking virtual machines by night ▶ PhD candidate in Language Interoperability @ fit.cvut.cz