Comparison and hashing archetype::IdentifierRef
s by address
#160
Labels
A - Storage
Area: Storage inside a World.
C - Enhancement
Category: New feature or request.
C - Performance
Category: Related to performance.
P - Low
Priority: Not particularly urgent.
S - Blocked on Dependency
Status: Cannot continue without a dependency implementing a feature.
S - Needs Investigation
Status: Further investigation is needed.
Currently, hashing is done by relying on the slice hash implementation: https://github.com/Anders429/brood/blob/master/src/archetype/identifier/mod.rs#L341. This eventually calls directly into
hash_slice
, which touches every element of the slice: https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-245This is inefficient for the case of
IdentifierRef
, for most use cases. Within theArchetypes
map, the key is the uniqueIdentifierRef
(see here: https://github.com/Anders429/brood/blob/master/src/archetypes/mod.rs#L80-L84), which will always be unique both value-wise and address-wise. If twoIdentifierRef
s in this context have different addresses, they will also have different values, invariantly. This is ensured because a newIdentifier
, and its subsequentIdentifierRef
, will only be created if one does not already exist in the table for the given entity signature.This, however, does not apply to serialization. For example, this test case: https://github.com/Anders429/brood/blob/master/src/archetypes/impl_serde.rs#L406 provides the same archetype identifiers for multiple archetypes, and is expected to fail because they hash to the same thing. In this case, the hashing should be done based on value; if it is done based on address, the current logic can't catch the duplicate.
It seems there are also some edge cases in the
Clone
implementations, but I don't have time to investigate those right now.It would be great to change the usages that shouldn't care about the values to just pay attention to the addresses. This would be more efficient, I believe.
The text was updated successfully, but these errors were encountered: