-
-
Notifications
You must be signed in to change notification settings - Fork 23.3k
Reduce cross project includes by rewriting HashMapHasherDefault
.
#106434
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
e0def9f
to
d22d390
Compare
dc37fe6
to
b2a441d
Compare
I've done some experiments and unfortunately this PR alone doesn't reduce build time, because all the headers removed from |
Thanks for checking! I was guessing as much, for the same reasons you mentioned; almost everything ends up including |
de9c7e5
to
0677326
Compare
13699cc
to
8c3514a
Compare
8c3514a
to
a144bab
Compare
…ble to declare a default hashing function for any type. Remove cross-project includes from `hashfuncs.h`. Improve hashing function for `Color` (based on values instead of `String`). Move `Variant` comparison from `hash_map.h` to `dictionary.cpp` (`VariantComparatorDictionary`), where it's used. Remove now unnecessary `HashableHasher`.
a144bab
to
6cb89ec
Compare
Godot is plagued by long compile times because of unnecessary cross project includes.
The main culprits are
hashfuncs.h
andvariant.h
.This PR eliminates cross project includes from
hashfuncs.h
, to improve compile time and reduce type coupling.Explanation
HashMapHasherDefault
was previously written by implementing astatic uint32_t hash(const T &)
function for every knownVariant
type. AsVariant
types grew, so did the includes forhashfuncs.h
.I rewrote the struct by adding a type trait called
HashMapHasherDefaultImpl<T>
. This type trait can be declared for any type, providing a hash function for default hashing, analogous toHashMapComparatorDefault
.The type trait is specialized for primitives (like
double
andint32_t
).It is further specialized for
enum
types by using the underlying type, which was also the previous behavior (through implicit conversion).It is also specialized for types that declare
uint32_t hash() const;
, by calling this function. This behavior was previously implemented withHashableHasher
, whose implementation claimed it is only possible to generalize this with c++20 concepts. I removed the now unnecessaryHashableHasher
type.Using this specialization, hash functions are moved to the appropriate types. By this move, the includes from
hashfuncs.h
could be removed.The same trick was applied to
HashMapDefaultComparator
, which previously had unnecessary specializations that all calledis_same
. I generalized this assumption with type trait logic (SFINAE).Side effects
Color
was previously hashed by converting toString
and hashing the string (through implicit conversion). This was slow. I optimized the conversion to hash with the components instead.hash_map
previously needed aVariant
include because it declared a function that assumedVariant
keys. I generalized the function to use a comparator, and moved the variant comparison method todictionary.cpp
(the only place where it was used). This allowed me to deletehash_map.cpp
.Color
). Two types now need to define an explicit hashing function that did not need to declare it before.enum struct
, which was not possible before. Previously, the enum needed to be implicitly convertible to its underlying type, to support being hashed byHashMapHasherDefault
.ImageLoaderSVG
remotely, to debug it I inserted the error code to the error message. It seems to have mysteriously disappeared, but I'd argue having the error code for the future is good anyway.