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

YJIT: Pack BlockId and CodePtr #6748

Merged
merged 1 commit into from Nov 16, 2022
Merged

YJIT: Pack BlockId and CodePtr #6748

merged 1 commit into from Nov 16, 2022

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Nov 16, 2022

This reduces memory usage on railsbench from 20.9MB to 18.2MB.

Before

code_region_size:         9895936
yjit_alloc_size:         20964221

After

code_region_size:         9732096
yjit_alloc_size:         18216757

@matzbot matzbot requested a review from a team November 16, 2022 21:45
@k0kubun k0kubun marked this pull request as draft November 16, 2022 21:53
@k0kubun k0kubun marked this pull request as ready for review November 16, 2022 21:58
@@ -59,7 +59,7 @@ pub trait Allocator {
/// We may later change this to wrap an u32.
/// Note: there is no NULL constant for CodePtr. You should use Option<CodePtr> instead.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)]
#[repr(C)]
#[repr(C, packed)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious how much this change to CodePtr alone affects things. This doesn't change the size but allows the pointer to be stored unaligned: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6f40323dcc2d2898fb01d2309d734102

Maybe the compiler sees this and gives struct Block a more compact layout?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has a relatively big impact for some reason.

With CodePtr not packed

code_region_size:         9715712
yjit_alloc_size:         19684821

With CodePtr packed

code_region_size:         9715712
yjit_alloc_size:         18179277

Copy link
Member

@XrXr XrXr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Good that Rust lets us do this without headache :)

@k0kubun k0kubun merged commit 3259ace into ruby:master Nov 16, 2022
@k0kubun k0kubun deleted the yjit-packed branch November 16, 2022 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants