The Limits of Copy-On-write: How Ruby Allocates Memory
brandur.org
brandur.org
If there's one takeway/point of interest that I'd recommend looking at, it's the novel way that Ruby shares a pointer value between actual pointers to memory and special "immediate" values that simply occupy the pointer value itself [1]. For example, a fixnum (most integers) has its binary value shifted by one bit to the left, and then a "1" flag applied in its rightmost position so that Ruby can recognize it. It doesn't have to go to heap, and the runtime can take advantage of that for faster calculations.
This is usual in Lisp (compilers/implementations) and i wouldn't be surprised if it was invented on the seventies once large (i.e. 36-bit long) registers were available.
https://www.snellman.net/blog/archive/2017-09-04-lisp-number...
(I just noticed that two of my articles are cited for that page. How neat!)
For more examples, Objective-C does this on 64-bit, and many Lisp implementations use it. Swift uses it for certain enum payloads.
An interesting variant is to stuff your pointers into the payload of an IEEE754 NaN value. This is popular in JavaScript, since JS numbers are IEEE754 doubles.
Copy of Mozilla's article presenting their switch to NaN tagging: https://evilpie.github.io/sayrer-fatval-backup/cache.aspx.ht... HN discussion with more history & links: https://news.ycombinator.com/item?id=1569825
That is how Lisps speedup list operations since it is the most used data structure.
Of course Obj-C already uses this for tagged-pointer numbers/strings/etc, so you've got competition if you want to start using this for something.