generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
A question raised during yesterday's plenary was if the creation of Composite's should eagerly intern/canonicalize, such that Composite({ x: 1 }) === Composite({ x:1 })
.
Upsides:
- "pay to play"
- not requiring any changes to existing equality checks avoiding adding new code branches which can have a cost even if the application is not using Composites
- No new equality
- Existing libraries/APIs would 'just work'
- Checking if two composites are equal would be one pointer equality check
Downsides:
- Composite creation becomes more expensive
- This would mean that unique symbol keys would not be possible
- Only sortable values are usable as keys
Symbol.iterator
could not be a key
- Could not do SameValueZero
- Would either be SameValue or
-0
is canonicalized to0
.
- Would either be SameValue or
- Some objects would need to be banned from
Weak{Map,Set}
- e.g.
Composite({ x: 1, y: 4 })
has no constituents that provide a non-infinite lifetime
- e.g.
- Potential for more garbage collection time due to added complexity
- e.g. A
WeakMap
whereComposite({ a: objectA, b: objectB, c: 42 })
is a key should remain in theWeakMap
until eitherobjectA
orobjectB
becomes unreachable - this applies deeply for composites made from other composites.
- e.g. A
- Prototype equality checks:
- This may close the door for non-null prototypes with cross-realm equality
- In a world where there are built in ordinal Composites (Tuples) with a
Tuple.prototype
to provideSymbol.iterator
and list methods such as.map
,.some
for these to still be equal across realms they would need to have a realm scoped[[prototype]]
lookup similar to primitives and the one being discussed for Shared Structs.
Important
The quantity of the above lists should not be interpreted as weights on different sides of a scale. 10 downsides could still be trumped by 1 upside.
One good next step here IMO is to get some empirical data from a prototype implementation to measure some of performance impacts of different designs with different application use cases. Maybe this will be a good time for me to learn how to build v8 and get a custom binary on to some mobile phones!
cc: @syg
qwertie, Maxdamantus, Ovyerus, SeregPie, nnmrts and 1 morefutpibslorber, travislwatson, controversial, tusharsadhwani, AleksandrSl and 2 moreMaxdamantus, slorber, transitive-bullshit, petamoriken, pickaxe828 and 2 more
Metadata
Metadata
Assignees
Labels
No labels