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

Improve Shapes Friendliness of Batch::Loader #153

Merged
merged 1 commit into from
Jan 16, 2023

Conversation

casperisfine
Copy link
Contributor

For optimal performance in Ruby 3.2, it is preferable to define instance variables in a consistent order.

Based on production data, it seems that Batch::Loader is one of the main offenders in our app:

Shape Edges Report
-----------------------------------
       169  @cache
       130  @queue
       127  @executor
       125  @sql_counter
       119  @loader_key

For optimal performance in Ruby 3.2, it is preferable to
define instance variables in a consistent order.

Based on production data, it seems that Batch::Loader is one of
the main offenders in our app:

```
Shape Edges Report
-----------------------------------
       169  @cache
       130  @Queue
       127  @executor
       125  @sql_counter
       119  @loader_key
```
@casperisfine casperisfine merged commit 8afc76f into master Jan 16, 2023
@casperisfine casperisfine deleted the shapes-friendliness branch January 16, 2023 14:30
@shopify-shipit shopify-shipit bot temporarily deployed to rubygems January 16, 2023 22:44 Inactive
@trevorturk
Copy link

I came across this and I'm curious to learn more.

Is this a quirk with Shapes and/or YJIT that might be ironed out in the future, or a performance optimization we should consider for our own apps and gems?

No pressure at all, of course, but a small writeup or blog post would probably be of interest to a lot of people like me!

@casperisfine
Copy link
Contributor Author

Is this a quirk with Shapes and/or YJIT that might be ironed out in the future, or a performance optimization we should consider for our own apps and gems?

It's a performance optimization. Generating too many shapes prevent caching instance variable access and efficient YJIT compilation. So it's not that it makes things worse than they were on 3.1, just that they prevent it from performing better.

but a small writeup or blog post would probably be of interest to a lot of people like me!

Right, I'm quite swamped right now, but that's definitely something we need to do. In the meantime Jemma's talk will likely satisfy your curiosity: https://www.youtube.com/watch?v=So-KvN3p-eE

@trevorturk
Copy link

Excellent, thank you for the info!

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.

4 participants