4 ms·
It's similar to the way V8 works. This idea has a huge drawback. An instance, can have different shapes depending on the order you discover the fields, by exam
by _old_dude_ 5y ago
It's similar to the way V8 works.
This idea has a huge drawback. An instance, can have different shapes depending on the order you discover the fields, by example, if you have a point(x,y), the shape is different if you assign @x first or @y first.
So even if a code is not polymorphic for a human, it is polymorphic at runtime.
In practice, doing a static analysis of the code (maybe only the constructors of the hierarchy) is still needed to alleviate this issue.
- chrisseaton 5y agoI can't remember how much of the data we put into the original paper, but we found that in practice idiomatic Ruby objects do generally have stable instance variable insertion order and so stable shapes. Unstable insertion order does introduce polymorphism that's true, but that's a fairly linear and gentle performance overhead. I wouldn't characterise this as a huge problem myself. Mis-predicting object layout if you try to do it statically like Rubinius does is a full-on performance cliff and pretty catastrophic.