sdk icon indicating copy to clipboard operation
sdk copied to clipboard

[dart2wasm] Improve hash codes of closures in dart2wasm

Open mkustermann opened this issue 1 year ago • 0 comments

Currently dart2wasm closures use this as hash code:

class _Closure {
  ...
  int get hashCode => runtimeType.hashCode;
  ...
}

This can be a big issue for any code that uses closures in sets / maps (as we did ourselves for JS interop) as it will often lead to different closures (not identical, not ==) but with same hash code flowing as keys into maps / sets. This will make the map/set behave as a linear data structure instead of a O(1) data structure.

We'd want to use the identity hash code of closures (making == agree with identical) for get:hashCode - except for instance tear-offs and partial instantiations (where we have to use the torn-off receiver & partial instantiated types as part of hash code).

/cc @osa1 Maybe this is something you could have a look at?

mkustermann avatar Feb 14 '24 11:02 mkustermann