From: "ko1 (Koichi Sasada)" <redmine@...> Date: 2012-07-25T18:51:27+09:00 Subject: [ruby-core:46756] [ruby-trunk - Feature #6763] Introduce Flonum technique to speedup floating computation on th 64bit environment Issue #6763 has been updated by ko1 (Koichi Sasada). > How do you implement object_id for non integer immediate values? Good point. It will be considered. Akr-san proposed that object id of Flonum object should be Bignum (enough big value), because it should be very rare case to use Flonum object id. ---------------------------------------- Feature #6763: Introduce Flonum technique to speedup floating computation on th 64bit environment https://bugs.ruby-lang.org/issues/6763#change-28425 Author: ko1 (Koichi Sasada) Status: Open Priority: Normal Assignee: Category: core Target version: 2.0.0 =begin = Abstract 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. = Background Ruby (CRuby) have a Float class to achieve floating number calculation. However, the Float object is allocated as object every time. For example, x = 0.0 a = b = 1.2 10.times{ 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 10.times{ x += (a + b) } No object allocated by the above code because Fixnum representation doesn't need object allocation (immediate value). = Proposal 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 [1]. In article [1], 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. [1] A Lightweight Representation of Floting-Point Numbers on Ruby Interpreter http://www.atdot.net/~ko1/activities/rubyfp2008.pdf http://www.atdot.net/~ko1/activities/rubyfp2008_PPL2008.pdf 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. =end -- http://bugs.ruby-lang.org/