
Increasing the size of Ruby objects to minimize CPU cache misses - phiggy
https://github.com/ruby/ruby/pull/495
======
riffraff
I wonder: couldn't it have been reduced to 4 words instead?

I seem to recall most RValue objects are actually smaller than 5 words and I
only remember class objects being this large. I may be completely off base
anyway.

~~~
FooBarWidget
No it couldn't. 5 words is the minimum amount of storage that Ruby needs for
representing all its core types.

------
programminggeek
It's amazing to me how at every level caching helps considerably, and yet it
is often one of the last things people seem to optimize.

~~~
FooBarWidget
Because it's not _easy_ to optimize for caching. The currently available tools
for doing so are primitive at best. It's very hard to gain good insight in
your program's cache behavior and very hard to figure out what you can do
about it. There is also very little available literature about cache
optimization.

~~~
_delirium
They tend to also be brittle optimizations if your code is not tied to a
specific platform, since cache behavior on different architectures and even
micro-architectures differs significantly.

------
NatW
looks like it's assigned to ruby core as a (potential) feature for 2.2
already!: [http://bugs.ruby-lang.org/issues/9362](http://bugs.ruby-
lang.org/issues/9362)

------
jamesaguilar
Another option, just annotate it with your compiler's cache alignment
attribute. That way you need not redo the size for each architecture.

~~~
plorkyeran
That'd just leave you with wasted space rather than making more space
available for storing things inline. For the real-world tests I would not be
at all surprised if the reduced number of heap allocations was a bigger source
of speedups than the more cache-friendly reads.

------
dschiptsov
Someone read "The lost art of C structure parking" by Mr. Raymond.))

