# Why was the object\_id for true and nil changed in ruby2.0?

**URL:** <https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557>\
**Category:** ruby-talk\
**Created:** [20 March 2013 05:47 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557 "2013-03-20T05:47:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [20 March 2013 05:47 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557/1 "2013-03-20T05:47:08Z")

</div>

irb(main):001:0\> true.object\_id  
=\> 20  
irb(main):002:0\> false.object\_id  
=\> 0  
irb(main):003:0\> nil.object\_id  
=\> 8

The values for true and nil were respectively 2, 4 in 1.9.3 and 1.8.7,  
but have been changed to 20, 8 in ruby2.0.0 - even though the id of  
false remains the same i.e. 0 and the ids for Fixnum maintains the same  
old 2n+1 pattern.

What's the reason behind this object\_id change?

Why was this change made? How is this going to help developers?

The full question can be seen here:

> <https://stackoverflow.com/questions/15506763/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0>

thanks!

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [20 March 2013 06:03 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557/2 "2013-03-20T06:03:43Z")

</div>

your question was already answered at stackoverflow:

> > Seems to be something to do with “flonums” – a technique for speeding up

floating point calculations on 64-bit:  
github.com/ruby/ruby/blob/v2\_0\_0\_0/include/ruby/ruby.h#L383-431 and  
ruby-forum.com/topic/4404164.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [20 March 2013 14:23 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557/3 "2013-03-20T14:23:11Z")

</div>

hm the forumtopic i linked was in english ...

hm okay, Flonums may be not the reason because they are only in 2.1dev

&nbsp;&nbsp;a = 1.1 + 1.2  
&nbsp;&nbsp;b = 1.1 + 1.2  
&nbsp;&nbsp;p(a.object\_id == b.object\_id)

this shows true on 2.1, its false on 2.0p0

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [20 March 2013 16:35 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557/4 "2013-03-20T16:35:31Z")

</div>

Well, there is a new answer on Stack Overflow.

Gentlemen over here might want to take a look:

> <https://stackoverflow.com/questions/15506763/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/15526818#15526818>

Seems legit... but I am not sure how can something like this lead to  
better perfomance? Any comments?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [20 March 2013 14:10 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557/5 "2013-03-20T14:10:20Z")

</div>

Hans Mackowiak wrote in post #1102392:

> your question was already answered at stackoverflow:
> 
> > > Seems to be something to do with “flonums” – a technique for speeding up
> 
> floating point calculations on 64-bit:  
> github.com/ruby/ruby/blob/v2\_0\_0\_0/include/ruby/ruby.h#L383-431 and  
> ruby-forum.com/topic/4404164.

I have tried to read it, but the presentations given in that link are  
written in Japanese, and I couldn't understand what Flonums are why they  
are implemented.

Know any place where I can read them in English to understand why it was  
changed?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [20 March 2013 16:22 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557/6 "2013-03-20T16:22:57Z")

</div>

Hans Mackowiak wrote in post #1102451:

> hm okay, Flonums may be not the reason because they are only in 2.1dev
> 
> &nbsp;&nbsp;a = 1.1 + 1.2  
> &nbsp;&nbsp;b = 1.1 + 1.2  
> &nbsp;&nbsp;p(a.object\_id == b.object\_id)
> 
> this shows true on 2.1, its false on 2.0p0

This shows true in my system too, but my ruby -v is ruby 2.0.0p0  
(2013-02-24 revision 39474) [x86\_64-linux], not 2.1.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Matthew\_Kerwin](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/matthew_kerwin/32/1845_2.png) [@Matthew\_Kerwin](https://rubytalk.org/u/Matthew_Kerwin)\
**Post date:** [20 March 2013 19:44 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557/7 "2013-03-20T19:44:33Z")

</div>

Because immediate values have no overhead. It takes memory and cpu cycles  
to create an object instance; it takes no (extra) memory if the value is  
stored in the reference (ie the object id \_is\_ the value, albeit slightly  
modified), and far fewer cycles to shift and OR some bits.

> **···**
>
> Sent from my phone, so excuse the typos.

---

<div class="post-metadata">

**Author:** ![D\_Deryl\_Downey](https://avatars.discourse-cdn.com/v4/letter/d/8baadc/32.png) [@D\_Deryl\_Downey](https://rubytalk.org/u/D_Deryl_Downey)\
**Post date:** [20 March 2013 14:27 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557/8 "2013-03-20T14:27:16Z")

</div>

ruby-forum.com/topic/4404164 specifically states why it was changed. Its a speed thing.

![](https://canada1.discourse-cdn.com/flex029/uploads/rubytalk/original/2X/0/02fa11a3de1fe32605e858d84f3b1dcef2045483.jpg)

> **···**
>
> > Bharadwaj Srigiriraju \<mailto:lists@ruby-forum.com\>  
> > March 20, 2013 10:10 AM
> > 
> > I have tried to read it, but the presentations given in that link are  
> > written in Japanese, and I couldn't understand what Flonums are why they  
> > are implemented.
> > 
> > Know any place where I can read them in English to understand why it was  
> > changed?
> > 
> > Hans Mackowiak \<mailto:lists@ruby-forum.com\>  
> > March 20, 2013 2:03 AM  
> > floating point calculations on 64-bit:  
> > github.com/ruby/ruby/blob/v2\_0\_0\_0/include/ruby/ruby.h#L383-431 and  
> > ruby-forum.com/topic/4404164.
> 
> --  
> D. Deryl Downey
> 
> &nbsp;&nbsp;"The bug which you would fright me with I seek" - William Shakespeare - The Winter's Tale, Act III, Scene II - A court of Justice.

---

<div class="post-metadata">

**Author:** ![11142](https://avatars.discourse-cdn.com/v4/letter/1/e0b2c6/32.png) [@11142](https://rubytalk.org/u/11142)\
**Post date:** [20 March 2013 16:28 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557/9 "2013-03-20T16:28:13Z")

</div>

This only should be true on 64bit Ruby 2.0.

> **···**
>
> On Wed, 20 Mar 2013 17:22:57 +0100, Bharadwaj Srigiriraju \<lists@ruby-forum.com\> wrote:
> 
> > Hans Mackowiak wrote in post #1102451:
> > 
> > > hm okay, Flonums may be not the reason because they are only in 2.1dev
> > > 
> > > &nbsp;&nbsp;a = 1.1 + 1.2  
> > > &nbsp;&nbsp;b = 1.1 + 1.2  
> > > &nbsp;&nbsp;p(a.object\_id == b.object\_id)
> > > 
> > > this shows true on 2.1, its false on 2.0p0
> > 
> > This shows true in my system too, but my ruby -v is ruby 2.0.0p0  
> > (2013-02-24 revision 39474) [x86\_64-linux], not 2.1.
> 
> --  
> Matma Rex

---

<div class="post-metadata">

**Author:** ![Adam\_Prescott](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@Adam\_Prescott](https://rubytalk.org/u/Adam_Prescott)\
**Post date:** [20 March 2013 14:38 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557/10 "2013-03-20T14:38:20Z")

</div>

I'm interested (as is Hans, I think) in understanding the specifics of  
the implementation and \_why\_ this leads to better performance. Looks  
like someone would have to translate the Japanese, though.

> **···**
>
> On 20 March 2013 14:27, D. Deryl Downey \<me@daviddwdowney.com\> wrote:
> 
> > ruby-forum.com/topic/4404164 specifically states why it was changed. Its a speed thing.

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [20 March 2013 16:31 UTC](https://rubytalk.org/t/why-was-the-object-id-for-true-and-nil-changed-in-ruby2-0/67557/11 "2013-03-20T16:31:23Z")

</div>

Bartosz Dziewoński wrote in post #1102469:

> **···**
>
> > On Wed, 20 Mar 2013 17:22:57 +0100, Bharadwaj Srigiriraju \> \<lists@ruby-forum.com\> wrote:
> > 
> > > (2013-02-24 revision 39474) [x86\_64-linux], not 2.1.
> > 
> > This only should be true on 64bit Ruby 2.0.
> 
> Yes.
> 
> On 32 bit systems the object\_id didn't change at all.
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
