-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Link hash table primes externally to prevent data duplication in binary #88178
Conversation
1ec7020
to
690b751
Compare
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 don't see how this functionally changes the code, so it seems like an decent optimization.
That's a good catch. Since C++17 is now supported and the guidelines promote using constexpr, you might want to see if keeping the table in the header and marking them |
I think I tried constexpr already and it didn't change anything in this case, but I'll try Edit: I've just confirmed it - |
690b751
to
3fca4d0
Compare
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 good. Nice change!
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.
Looks great! Thanks for the initiative looking into optimizing binary size and memory usage, that's very welcome :)
Thanks! |
I've started analyzing Godot binaries on Windows using SizeBench and on top of the duplicate data results were
hash_table_size_primes
andhash_table_size_primes_inv
.As visible above the tool shows around 168KB of wasted memory (tested on commit 36e943b
scons target=template_release debug_symbols=yes
)This PR reduces build size by 547KB (
scons target=template_release
).File scoped const arrays are linked internally which means each time
hashfuncs.h
are included, those two arrays are not merged into single data point (which would be fine and expected for const, read only data).I've moved their initialization toThanks to @Malcolmnixon suggestion I've made it simpler by usinghashfuncs.cpp
and markedextern
inhashfuncs.h
.inline constexpr
from C++17 standard.I've not benchmarked it yet. In theory it can improve the CPU cache, because all of the hash_maps and hash_sets reuse the data from the same address in memory (meaning - there is higher chance that it will be still present in cache when needed).