-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Align structures for 64bit platforms for improve putting to CPU cacheline #18559
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
base: master
Are you sure you want to change the base?
Conversation
Also, information to all developers, make it a rule to try to make structures and classes smaller than 64 bytes. |
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.
phpdbg seems broken. Tests are failed.
lxb_css_float_type_t type; | ||
lxb_css_value_length_type_t length; | ||
lxb_css_float_type_t type; |
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.
Please, don't change the bundled third-party libraries without a big reason.
int sizearray; | ||
struct Table*metatable; | ||
TValue*array; | ||
Node*node; | ||
Node*lastfree; | ||
GCObject*gclist; | ||
int sizearray; |
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 is also third-party software.
Hi @GermanAizek. Thank you for your contribution. As @dstogov mentioned, lexbor, libmagic and dynasm should not change. If these need to be adjusted, it should be done upstream first. Adjusting the other structs should be ok, though note sometimes it's more important to place things that are frequently accessed together close together to increase the chances of them landing on the same cache line. But I don't see any issues with the changes you have made. |
…heline affected structs (decreased sizes): _phpdbg_breakbase_t 32 to 24 bytes lxb_css_property_float_t 40 to 32 bytes _phpdbg_breakop_t 40 to 32 bytes zend_hooked_object_iterator 160 to 152 bytes _phpdbg_breakcond_t 152 to 136 bytes lxb_css_selectors_pseudo_data_func_t 72 to 64 bytes _phpdbg_breaksymbol_t 32 to 24 bytes _zend_smm_shared_globals 80 to 72 bytes lxb_encoding_ctx_2022_jp_t 16 to 12 bytes _phpdbg_command_t 80 to 72 bytes lxb_css_syntax_token 104 to 96 bytes _phpdbg_breakopline_t 72 to 64 bytes cdf_directory_t 136 to 128 bytes _phpdbg_breakfile_t 40 to 32 bytes err_buf 32 to 24 bytes phpdbg_lexer_data 48 to 40 bytes Table 64 to 56 bytes _phpdbg_breakline_t 48 to 40 bytes glob_s_t 144 to 136 bytes _phpdbg_breakmethod_t 56 to 48 bytes _php_netstream_data_t 40 to 32 bytes
Hi everyone, thank team so much for development PHP interpreter.
I think this PR will reduce minimum requirements for hardware, and it will decrease costs copying, moving, and creating object-structures only for common 64bit processors due to the 8-byte data alignment.
Smaller size structure or class, higher chance putting into CPU cache. Most processors are already 64 bit, so the change won't make it any worse.
Info about technique:
https://hpc.rz.rptu.de/Tutorials/AVX/alignment.shtml
https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-14-haase-svenhendrik-alignmentinc-presentation.pdf
https://en.wikipedia.org/wiki/Data_structure_alignment
https://stackoverflow.com/a/20882083
https://zijishi.xyz/post/optimization-technique/learning-to-use-data-alignment/
Pahole log:
/* XXX {n} bytes hole, try to pack */
shows where optimization is possible by rearranging the order of fields structures and classesMaster branch
My PR changes:
Affected structs (decreased sizes):