martes, 21 de agosto de 2012

Fastruby 0.0.22: optimized dynamic calls

Fastruby is a gem which allows to execute ruby code much faster than normal, currently in a state of transition between a spike and a usable gem, it is released when possible with incremental improvements.

In previous post I promised to Improve speed of dynamic call lookups, this is because the speed optimization used to depend heavly on the possibility of inlining and therefore on the type information found at build-time. When no type information for method call receivers can be obtained at build-time, the method call is encoded as dynamic, and the method used to resolve dynamic calls so far was not optimal leading to results significantly worst than MRI 1.9

For example, the next code run faster because of the type information provided by lvar_type directive


  1. class Y  
  2.   def bar(x)  
  3.     i = 1000000  
  4.     lvar_type(i,Fixnum)  
  5.      
  6.     ret = 0  
  7.     while i > 0  
  8.       ret = x.foo(i,i)  
  9.       i = i - 1  
  10.     end  
  11.     return ret  
  12.   end  
  13. end  

Else, removing lvar_type:


  1. class Y  
  2.   def bar(x)  
  3.     i = 1000000  
  4.     #removed lvar_type  
  5.      
  6.     ret = 0  
  7.     while i > 0  
  8.       ret = x.foo(i,i)  
  9.       i = i - 1  
  10.     end  
  11.     return ret  
  12.   end  
  13. end  

Will result on this (for version without lvar_type):

Before (v0.0.21 and prior)

Now:






NOTE: When lvar_type is used, the results are the same as in v0.0.21 (see this post)

Next