[NFR] Reorder struct fields to save some memory #891
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is mostly useful for x86_64 architecture because pointers are larger than plain integers.
Example:
pointers are 8 bytes, integers are 4 bytes; pointers must be aligned at 8 bytes boundary, integers at 4 bytes boundary; thus, after
opcode
there will be a padding 4 bytes long. Plus, the structure itself will have to be padded to 8 bytes boundary.Therefore, the actual size will be (4+8+4)+4+4=24 bytes; 16 bytes are payload, 8 bytes are padding.
If we move
value
to the front:value
will be at 8 bytes boundary andopcode
andlen
will be at 4 bytes boundary; the size of the structure is 16 bytes (a multiple of 8) and the structure does not have to be padded.Thus, reordering in this case allowed to reduce the size of the structure in 1.5 times. Not bad.