The myth of dynamic language performance

B012094b37ab6946c44eaa41d7828478?s=47 Dirkjan Bussink
June 20, 2013
340

The myth of dynamic language performance

Talk at DevConTLV about how to make your dynamic language implementation faster. What are some basic techniques used and how do they work.

B012094b37ab6946c44eaa41d7828478?s=128

Dirkjan Bussink

June 20, 2013
Tweet

Transcript

  1. The myth of dynamic language performance DevConTLV

  2. Dirkjan Bussink @dbussink

  3. Rubinius A Ruby implementation

  4. None
  5. “PHP too slow for Facebook, builds its own faster version”

    “Everything you heard about Ruby being slow is not true. It’s about twice as slow as that” “How JavaScript is Slowing Down the Web” 2006
  6. None
  7. None
  8. None
  9. Static vs. Dynamic

  10. Weak vs. Strong

  11. C PHP Java Ruby Static Dynamic Weak Strong

  12. None
  13. The lure of the hash table

  14. class MethodTable def initialize @methods = {} end def store_method(name,

    code) @methods[name] = code end def find_method(name) @methods[name] end end
  15. class Address { private String street; private Integer number; private

    String city; public Address(String street, Integer number, String city) { this.street = street; this.number = number; this.city = city; } }
  16. class Address { private HashTable<String, Object> instance_variables; public Address(String street,

    Integer number, String city) { instance_variables = new HashTable<String, Object>(); instance_variables.put("street", street); instance_variables.put("number", number); instance_variables.put("city", city); } }
  17. Hash tables everywhere!

  18. Inline caching

  19. p = Person.new p.name <receiver_class_id, code>

  20. Specific object layout

  21. class Address attr_reader :street attr_reader :number attr_reader :city end Address.instance_variable_get("@seen_ivars")

    => [:@street, :@number, :@city]
  22. 0001: push_ivar :@number self[1] Removes hash table lookup

  23. Just in time compilation

  24. def method1 1 + method2 end def method2 2 +

    1 end 100000.times do method1 end ... 0x110ed90e7 mov $0x9, %eax 0x110ed90ec jmp 0x119 ; 0x110ed9129 ... 0x110ed9129 addq $0xa0, %rsp 0x110ed9130 pop %rbp 0x110ed9131 ret 1 + 2 + 1 = 4 FIXNUM(4) = 0x9
  25. What about you as a developer?

  26. Be nice

  27. Write type stable code

  28. Small and simple methods

  29. Benchmark!

  30. Recap

  31. Fast dynamic languages are harder, not impossible

  32. Writing simple and well factored code is often easy to

    optimize for a VM
  33. ?