Let’s say I have a pair of objects setup in a publish-subscribe
manner. Object A communicates to Object B by creating and sending a
new instance of class C for every publish.
class A
include Observable
def publish
changed
notify_observers(C.new(some_data))
end
end
class B
def update(message)
# do something with message
end
end
class C
def initialize(data)
long_and_complex_computation(data)
end
end
In this scenario, class C’s constructor is called every time a new
message is sent (could be many thousands of times). Is it ever JIT’ed
even though it only gets called once per object?
The JIT counter is actually on the interpreted version of the method.
So regardless of which object is calling the method, once that method
has been called enough times it tries to JIT the method. So it should
JIT in this scenario.
I don’t see why the C constructor wouldn’t be JIT compiled. Most JIT
compilers, that I know of, compiles on the basis of classes, not object
instances.
This is, of course, assuming that you don’t constantly redefine
C#initialize
or that long_and_complex_computation does not execute any dynamic string
evals.
Peter
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.