-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Shrink some commonly used structs by reordering members #10880
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
Conversation
Struct members require some alignment based on their type. This means that if a struct member is not aligned, there will be a hole created by the compiler in the struct, which is wasted space. This patch reorders some of the most commonly used structs, but in such a way that the fields which were in the same cache line still belong together. The only exception to this is exception_ignore_args, which was temporally not close to nearby members, and as such I placed it further up to close a hole. On 64-bit Linux this gives us the following shrinks: * zend_op_array: 248 -> 240 * zend_ssa_var: 56 -> 48 * zend_ssa_var_info: 48 -> 40 * php_core_globals: 672 -> 608 * zend_executor_globals: 1824 -> 1792 On 32-bit, the sizes will either remain the same or will result in smaller shrinks.
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 personally don't think optimizing space for globals is super important, but I feel indifferent on changing it. The change for zend_op_array
seems to save 4 bytes which seems useful. Same for the SSA structures.
8 bytes ;) |
Ah, right 🙂 |
Oh, one thing I forgot to mention regarding globals is that although the space save won't be impressive, it's good for reducing data cache pressure. |
Also true. Grouping data that is frequently accessed together definitely makes sense. |
Changed to bool and added entry to UPGRADING.INTERNALS |
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.
LGTM, thanks @nielsdos 🙂
would it be fair to ask another opinion (e.g. Dimtry) ? |
@devnexen Sure 🙂 |
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.
This looks fine.
Struct members require some alignment based on their type. This means that if a struct member is not aligned, there will be a hole created by the compiler in the struct, which is wasted space. This patch reorders some of the most commonly used structs, but in such a way that the fields which were in the same cache line still belong together. The only exception to this is exception_ignore_args, which was temporally not close to nearby members, and as such I placed it further up to close a hole.
On 64-bit Linux this gives us the following shrinks:
On 32-bit, the sizes will either remain the same or will result in smaller shrinks.
There should be almost no BC impact. There is one BC caveat which can also be seen with the change to zend_executor_globals: if code initializes the struct in a way that's position dependent, then the order of the initialization needs to be changed too. This happened in Zend/zend_execute.c. If these kind of things are unacceptable, I can drop the ones which are externally most likely to be visible. (or we can drop the PR if this idea is considered unacceptable as a whole)
Perhaps this also needs an UPGRADING.INTERNALS note if this gets merged.
I don't know whether we want this kind of change, I'm not strongly married to the idea. This PR is only a first step.