You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enable zero-allocation conversion between Atom's from different static atom sets #293
It would be useful to be able to cheaply convert between an Atom<StyloAtomSet>, an Atom<ServoAtomSet>, a DefaultAtom, etc. This would allow for interop between different crates without a performance penalty and without them all needing to coordinate on which set of static atoms to use.
However currently a dynamically allocated Atom is keyed by it's hash and that hash varies between static atom sets. So converting between Atom types requires reallocating.
I believe that implementing this would involve changing the Hash implementation of Atom to hash the content of the Atom rather than 64 bit value (see also #224 for why this may be a good anyway). At which point
Zero-allocation conversion would be nice but I think it’s incompatible with hashing &str once instead of twice when interning a string.
At the moment for non-inline atoms, we first call phf_shared::hash with a static-set-specific key to get a static-set-specific hash, use that hash to check if the atom is static, and if not reuse the same hash to look up the string in the dynamic set in case it’s already there. For the dynamic set hash to be independent of the static set, we’d have to hash the string twice with different hash functions.
(I think we can and should use 64 bits hashes but that doesn’t change the above.)
Activity
SimonSapin commentedon Aug 20, 2026
Zero-allocation conversion would be nice but I think it’s incompatible with hashing
&stronce instead of twice when interning a string.At the moment for non-inline atoms, we first call
phf_shared::hashwith a static-set-specific key to get a static-set-specific hash, use that hash to check if the atom is static, and if not reuse the same hash to look up the string in the dynamic set in case it’s already there. For the dynamic set hash to be independent of the static set, we’d have to hash the string twice with different hash functions.(I think we can and should use 64 bits hashes but that doesn’t change the above.)