Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dup on unbound method #519

Open
wants to merge 1 commit into
base: v3.2.1-pshopify4
Choose a base branch
from

Conversation

eileencodes
Copy link
Member

In Rails _read_attribute is defined on the top level ActiveRecord::Base rather than the subclasses. This results in object shapes not being able to use their cache. By implementing dup on unbound methods we can give each subclass a uniq iseq and unique inline cache, increasing our shape cache hits.

Note: experimental change that must be paired with changes to Active Record to see results.

In Rails `_read_attribute` is defined on the top level
ActiveRecord::Base rather than the subclasses. This results in object
shapes not being able to use their cache. By implementing `dup` on
unbound methods we can give each subclass a uniq iseq and unique inline
cache, increasing our shape cache hits.

Note: experimental change that must be paired with changes to Active
Record to see results.
@eregon
Copy link

eregon commented Jun 26, 2023

I think it would be rather unexpected that UnboundMethod#dup copies the bytecode when e.g. UnboundMethod#clone doesn't and generally .dup/.clone are not deep, they are only shallow copies.
I think another method name would be warranted.

One way would be to class_eval that method definition in different subclasses to ensure copying the bytecode. That would avoid exposing such an implementation detail.

@eregon
Copy link

eregon commented Jun 26, 2023

Ah sorry, this is Shopify/ruby, not ruby/ruby. I guess the experimental/draft PR is implicitly there then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants