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
YJIT: Compress BranchGenFn and BranchShape #7401
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the idea here. I think it also allows us to derive Debug on Branch
now because the function pointer is gone. But, I think this conflicts with the raw pointer change I'm trying a bit. In particular, the gen_fun never changes for a branch, but its shape can, so in my diff I have { gen_fun: Fun, shape: Cell<BranchShape>, .. }
to show this. I mean, it's not a huge problem and I can just make a new copy with the new branch shape and just have Cell<Fun>
. I think I'd prefer that the mutability of the shape is in contrast though. I think both representation should give the Branch
struct the same layout in the end (it recursively pulls out and aggregate enum variant bits at the top level). Change this if you want, it's not a big deal.
EDIT: actually, having the enum reflect the fact that some gen funs should/can only have the default shape (it's implicit), the representation here is probably better than being able to see the mutability of shape for some of the variants.
Just wanted to say I love this change. Makes the code much more readable. Thanks for the great change :) |
Nice. I did so in 6b9dda5.
Yeah, I want to keep that property.
I wonder if you can make it |
By the way, the fact that we couldn't |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really minor comments, othewise ready to merge.
Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
We have only a few variants of
BranchGenFn
. Using this property, we could use an enum to represent each function and set it instead of a function pointer, which is the core idea of this PR.I also made another change, making
BranchShape
part of theBranchGenFn
enum, which I believe contributes to its readability since it's made obvious that some functions don't useBranchShape
s other thanDefault
. (I hoped it would make an enum of an enum 1 byte like #7368, but this time it didn't seem to work. But I want to keep this change anyway)This reduces
yjit_alloc_size
by 0.28MB (3.1%) on 25 itrs of railsbench with arm64-darwin22 stats build.Before
After