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

reduce memory footprint for struct fields #27

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

cia-rana
Copy link
Contributor

@cia-rana cia-rana commented Dec 5, 2023

There is no memory allocation by the zero-sized type (ZST) field itself, but the footprint of the struct may increase depending on the order in which struct fields are defined. In fact, the sample code below shows an increase of 8 bytes.

https://go.dev/play/p/fsAXJ17soKK

So reorder the fields to save the footprint.

ref. golang/go#58483 (comment)

@Code-Hex
Copy link
Owner

Code-Hex commented Dec 6, 2023

@cia-rana Thank you so much!

@Code-Hex Code-Hex merged commit 30c0707 into Code-Hex:main Dec 6, 2023
2 checks passed
@cia-rana cia-rana changed the title reduce memory allocation for struct fields reduce memory footprint for struct fields Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants