Skip to content

Commit

Permalink
README mentions object-shape optimization
Browse files Browse the repository at this point in the history
(mostly explaining what to read and not to worry about it, but also how
to call clear_memery_cache! to set up the ivar in the initializer)
  • Loading branch information
nevinera committed Dec 30, 2023
1 parent 7499f7b commit a856df6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ a.users {}

However, this solution is kind of hacky.

## Object Shape Optimization

In Ruby 3.2, a new optimization was introduced that relies on tracking "object shape", and has negative interactions with dynamically added instance variables (introduced after initialization-time). See [here](https://bugs.ruby-lang.org/issues/18776) for details, or [here](https://railsatscale.com/2023-10-24-memoization-pattern-and-object-shapes/) for an explanation of the relevance (though both are already somewhat out of date by Ruby 3.3), but fundamentally Memery has substantial advantages over standard memoization techniques here - it introduces only _one_ new instance variable after initialization (`@_memery_memoized_values`), and doesn't expand the object-shape tree substantially. But if you are _desperate_ to confine a particular class to a single object-shape, you can call `clear_memery_cache!` in your initializer to set the instance variable ahead of time.

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tycooon/memery.
Expand Down

0 comments on commit a856df6

Please sign in to comment.