Revert the changes to the cache of externs in Store#323
Conversation
…nd `Global` objects in the `Store`, which avoids having to explicitly accessing the `__private` field (because the whole struct is now compared)." This reverts commit f4e6e57.
Curious how you caught the perf impact? Is there anything we can add to the project that would catch this in CI? |
After submitting the PR, I wasn't sure how the default However, then I took a look at how the equality check is performed by default for value types, and found that Thanks! |
Revert the changes to the cache of externs in
Storefrom #318, as those would have negative performance impact.When looking up a value in the dictionary, it would use the
Equals(object)method on the struct which causes the struct to be boxed. Additionally, the defaultValueType.GetHashCode()apparently doesn't incorporate the value of[U]IntPtr/n[u]intfields, so we would also need to implementGetHashCode()in theExtern...structs.Instead, we use a
ValueTupleas key consisting of the extern type and the the both struct fields, like it was done previously (ValueTuple<...>implementsIEquatable<T>to avoid boxing, and uses all elements for calculating the hash code).It should be Ok to access the
__privatefield of theExtern...structs, because we don't interpret its value in any way, and just use it to compare the value to other struct instances.