apollo-rs
apollo-rs copied to clipboard
TypeDefinition should implement lightweight identity hashing rather than `derive(Hash)`
The TypeDefinition
enum derives the Hash
trait, which is extremely slow for large types. For example, this simple wrapper struct that just hashes typename provides a dramatic improvement when inserting type definitions into hashmaps and hashsets:
#[derive(PartialEq, Eq)]
struct TypeKey {
ty: TypeDefinition,
}
impl Hash for TypeKey {
fn hash<H: Hasher>(&self, state: &mut H) {
self.ty.name().hash(state);
}
}
Compiler should do this directly and implement a custom Hash
trait for TypeDefinition that uses minimally unique criteria. I suspect that the derived hash implementation gets into fields, making larger types hash increasingly slowly.