---
# System prepended metadata

title: Title

---

# Title
#### Publicly viewable title. Make sure it's interesting and expresses the essence of the talk

Implementing Object Shapes in CRuby

# Abstract
#### A concise, engaging description for the public program. Limited to 1000 characters.

Object Shapes are a technique for representing properties of an object that can increase cache hits in instance variable lookups, decrease runtime checks, and improve JIT performance. In this talk, we'll learn all about the CRuby implementaion of Object Shapes, including how they work, why implement them, and interesting implementation details.

# Details
#### Include any pertinent details such as outlines, outcomes or intended audience.

This talk will begin by describing what object shapes are, how they work, and why to use them. It will then address a few technically interesting aspects of object shapes. Finally, it will demonstrate the performance implications of object shapes.

The intended audience is anyone interested in Ruby internals. The intended outcome is for the audience to learn all about object shapes, and why we implemented them in CRuby.

Here's an outline for the talk:
 
[10 minutes] Intro to Object Shapes
* An object’s shape is defined by specific properties, including its instance variables
    *  For example, two objects which define only  `@name` and `@id` in that order would have the same object shape, regardless of their classes
* Object shapes decouple ivar lookup from the class of the object
* Each object shape has a unique ID, stored on the object itself
* With each instance variable instantiation, the shape of an object changes
    * Give examples, including diagrams of shape transitions and transformations
* The frozen status of an object is also encoded in its shape

[10 minutes] Why use object shapes?
* We can cache these instance variable transitions based on object shapes, instead of on classes of objects
* Decrease runtime checking
    * We currently store the frozen status of an object on the shape. This means that we no longer need to check the frozen status on a cache miss, only on a cache hit.
* Instance variable access is so common that refactoring it to enable just in time compilers (JITs) to optimize it can improve overall performance of JITs
    * Show assembly code JITs generate on instance variable access with and without shapes
    * Demonstrate the change in number of assembly code instructions
    * Show statistics of actual performance improvements from Object Shapes

[7 minutes] Interesting implementation details of shapes
* Garbage collection of shapes
    * Shape GC gives us the ability to reuse shape IDs and minimize memory impact
    * There's a shape list stored on the VM, and we use a bitmap lookup to efficiently find available shape IDs
* No cache shape path
    * Even given shape GC, there's still a way to run out of shapes
    * We implemented a NO_CACHE_SHAPE to use when there are no longer available shapes
 
[3 minutes] Q&A / Buffer time

# Pitch
#### Explain why this talk should be considered and what makes you qualified to speak on the topic.

At last year’s Ruby Kaigi, [Chris Seaton’s keynote](https://rubykaigi.org/2021-takeout/presentations/chrisgseaton.html) suggested CRuby adopt object shapes, and [Maxime Chevalier-Boisvert’s talk](https://rubykaigi.org/2021-takeout/presentations/maximecb.html) discussed the potential YJIT performance improvements from implementing object shapes. Largely inspired by these talks, I have been working alongside Aaron Patterson and Eileen Uchitelle on an object shapes implementation for CRuby.

We have already [received positive feedback from Koichi](https://bugs.ruby-lang.org/issues/18776) on our work to date on object shapes. It is likely that object shapes will be merged into CRuby before Ruby Kaigi. If this is the case, Ruby Kaigi will be the first opportunity to give a talk about the specific CRuby implementation of object shapes.
 
I am qualified to speak on this topic because, alongside Aaron and Eileen, I have written the CRuby implementation of object shapes. I also have experience giving approachable talks on deeply technical topics. I spoke at RailsConf 2021 about the internals behind Ruby Objects, and at RubyConf 2021 about optimizing performance when metaprogramming. Both of these talks were well received, and have made me confident in my ability to tackle the topic of object shapes in an understandable way.


# Bio
#### Your bio should be short, no longer than 500 characters. It's related to why you're speaking about this topic.
 
Jemma Issroff works on Shopify's Ruby Infrastructure team. She is also a co-founder of WNB.rb, a women and non-binary Ruby community, a co-host on *The Ruby on Rails Podcast* and the author of Ruby Weekly's *Tip of the Week*. She has been working on an implementation of Object Shapes in CRuby and is excited to share it with you!
