-
Notifications
You must be signed in to change notification settings - Fork 127
Reorganise structs layout to improve mem padding #437
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
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 didn't aware about this and I feel curious, what is the reasoning behind it? How does it work? grouping fields by type?
@mcarmonaa - couple readings:
(or just by searching about go memory alignment), but briefly - memory aligns to 8 bytes (most likely but it depends on architecture), so if you layout your structure like:
because of 8bytes alignment, compiler will introduce memory padding, so it will look:
and thats why you'll loose 10 bytes. But if you layout your structure for instance as follows:
you'll loose just 2 bytes (I think the last padding is OK):
Generally, the simplest thing what I do I just layout structure from the biggest type to the smallest. |
Thank you very much @kuba-- for such a good explanation and the links! ✨ |
engine *sqle.Engine | ||
pool *gitbase.RepositoryPool | ||
name string | ||
SkipGitErrors bool // SkipGitErrors disables failing when Git errors are found. |
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 changing the output of gitbase server --help
command? If yes, could you change it on the documentation too please?
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.
@ajnavarro - done
Signed-off-by: kuba-- <kuba@sourced.tech>
Signed-off-by: kuba-- kuba@sourced.tech
Closes #436
This is a small thing, but maybe worth to consider (WDYT)?. As an example I re-organized couple structs to make memory alignment optimal - less work for GC.
Changes:
Server
size was 192, now 176squashReposIter
size was 80, now 72squashRefIter
size was size 112, now 104squashCommitFilesIter
size was 120, now 112squashIndexCommitFilesIter
size was 128, now 120