Speeding Ducks
Avi Bryant
Speeding Ducks Avi Bryant Meta Heckling welcomed. Ruby is slow - - PowerPoint PPT Presentation
Speeding Ducks Avi Bryant Meta Heckling welcomed. Ruby is slow So what? Of course! So what? The Ruby language may be slow, but my app runs plenty fast True. Ruby ary.pop C VALUE rb_ary_pop(ary) VALUE ary; {
Speeding Ducks
Avi Bryant
Meta
Heckling welcomed.
“So what?” “Of course!”
So what?
“The Ruby language may be slow, but my app runs plenty fast”
True.
Ruby
C | Java | Smalltalk | ...
def pop() return nil if empty?vs
def pop() return nil if empty?Of course!
“Ruby is inherently slow because it is so dynamic.”
False.
Smalltalk-80
Efficient Implentation of the Smalltalk-80 System
Alan M. Schiffman 1984
Deutsch, 1984 - Native Code
def foo(duck) duck.waddle end mov ... cmp ...
cache
Deutsch, 1984 - Native Code
def foo(duck) duck.quack! end mov ... cmp ...
invalid
Deutsch, 1984 - Inline Caching
def foo(duck) duck.quack! end address = lookup(duck, :quack!) push duck jump(address) def quack! puts “quack” end ...
0xBEEF 0xDECAF
Deutsch, 1984 - Inline Caching
def foo(duck) duck.quack! end def quack! puts “quack” end ...
0xBEEF 0xDECAF
push duck jump(0xBEEF)
Deutsch, 1984 - Inline Caching
def foo(duck) duck.quack! end def quack! puts “quack” end
0xBEEF 0xDECAF
push duck jump(0xBEEF) unless self.class == Duck jump(lookup(self.class, :quack!) end ...
Deutsch, 1984 - Inline Caching
def foo(duck) duck.quack! end def quack! play “q.wav” end
0xBEEF 0xDECAF
push duck jump(0xBEEF) unless self.class == Duck jump(lookup(self.class, :quack!) end ...
Deutsch, 1984 - Inline Caching
def foo(duck) duck.quack! end def quack! puts “quack” end
0xBEEF 0xDECAF
push duck jump(0xBEEF) unless self.class == Duck jump(lookup(self.class, :quack!) end ... address = duck.vtable[3] jump address
SOAR: Smalltalk without Bytecodes
David Ungar Dain Samples Paul Hilfinger 1986
Self
Customization: Optimizing Compiler Technology for Self
David Ungar Craig Chambers 1989
Optimizing Dynamically-Dispatched Calls with Run-Time Type Feedback
David Ungar Urs Hölzle 1994
Self - Polymorphic Inline Caches
def foo(duck) duck.waddle end
Duck: 42 Goose: 7 Doctor: 1
Self - Type feedback inlining
def foo(duck) duck.quack! end def quack! puts “quack” end if duck.class == Duck puts “quack” else ... end
Self - Type feedback inlining
def foo(range) range.collect{|x| x * 2} end def foo(range) result = [] range.each do |x| result.push(x * 2) end result end
Self - Type feedback inlining
def foo(range) range.collect{|x| x * 2} end def foo(range) result = [] i = range.first while(i <= range.last) result.push(i * 2) i += 1 end result end
Self - Type feedback inlining
def foo(range) range.collect{|x| x * 2} end def foo(range) result = [] i = range.first while(i <= range.last) result.push(i << 1) i = i + 1 end result end
Strongtalk
Ungar, Hölzle, Lars Bak, et al
HotSpot
JavaScript