Introduce Flonum technique to speedup floating computation on th 64bit environment
Introducing Flonum technique, which is similar to Fixnum against Integer, to speedup floating number calculation on the 64bit CPU.
On our measurements, we can achieve x2 performance improvement for simple floating calculation.
Ruby (CRuby) have a Float class to achieve floating number calculation. However, the Float object is allocated as object every time.
x = 0.0
a = b = 1.2
x += (a + b)
It create over 20 floating number objects.
(a+b) creates one Float object and x+=(a+b) create one more.
This is a one of the biggest reasons why floating number calculation is slow using (C)Ruby.
On the other hands, Fixnum calculation doesn't make new object.
x = 0
a = b = 1
x += (a + b)
No object allocated by the above code because Fixnum representation doesn't need object allocation (immediate value).
Introducing Flonum technique for Float such as Fixnum for
Integer on the 64bit CPU enviroment.
A limited ranged Float object can be represented similar way of
Fixnum (immediate object).
Accuracy of the floating calculation is not affected.
We already have tried preliminary implementation and evaluation .
In article , I describe a technique to introduce Flonum into
CRuby on 64bit CPU environment.
Key idea of our technique is represent a small Float object (mantissa is small enough)
in special bit pattern.
Otherwise, a big float numbers are represented by current object representation.
 A Lightweight Representation of Floting-Point Numbers on Ruby Interpreter
Sorry, they are written in Japanese.
Note that we need to change the technique described in this article because proposed technique uses the Fixnum bit pattern for Flonum.
On our implementation, class of Flonum object is Float class.
It is different relation from the relation between Fixnum and Integer.
I think it is a point to discuss.
I heard that MacRuby has similar optimization.
= Compatibility issue
(1) A result of float calculation always return different object if it is same result
a = 1.1 + 1.2
b = 1.1 + 1.2
p(a.object_id == b.object_id) #=> false
After introducing flonum, it will be same objects.
(2) Breaking binary compatibility for C extension
Now, Float object is always `struct RFloat' data type.
After introducing Flonum, the assumption will be break.