is Ruby
slow
?
TDC2012 São Paulo
OH: sometimes, if you really care about performance, you need to write C in Java
Ruby <3
2.times { puts "yay!"}
Ruby <3
2.send(:times) { puts "yay!"}
{:methods => {:times => ...}}
hashmap!
calling a method
- get the object
- lookup the method
- call it
- profit
lookup a method?
seems legit
lookup a method?
class A
def lol; puts "lol"; end
end
class B < A; end
class C < B; end
lookup a method?
C.new.lol
lookup the method
C.new.methods.include? :lol
=> true
modules
module X
def beep
puts "beep beep"
end
end
modules
class C
include X
end
open classes
class A
def lol
puts "wut"
end
end
open classes
> C.new.lol
wut
=> nil
this is
amazing
and dangerous
classes are
mutable
Objects
innocuous code
my_hash = {}
class << my_hash
include X
end
innocuous code?
10.times do
Thread.new do
my_hash = {}
class << my_hash
include X
end
end
end
double dispatch
(almost)
kills
inlining
Car.find_by_name
method_missing
method_missing
also known as
binding
x = "hello"
eval("puts x")
hello
=> nil
inconstants
A_CONSTANT = 3
A_CONSTANT = 4
warning: already initialized constant A_CONSTANT
>> A_CONSTANT
=> 4
what about
Garbage Collection?
what about
Threading?
(and GIL)
implementation-specific
JRuby
YARV
Rubinius
MagLev
MRI
pick your poison
censored
biased speaker
JRuby wins ;)
late dispatch?
open classes?
inlining
ALL THE THINGS
kidding
JRuby makes the method calls
inlinable
let the
JVM
do the dirty work
it's all about
trade-offs
Ruby's goal is to make programmers
happy
with great power comes great responsability