Suggest Object.compare(lert, right)

Park Hyeonu nemo1275 at gmail.com
Mon Sep 19 10:05:13 UTC 2016


Um, then it's reasonable implementation. But it can be far much optimized
with native implementation(naively say, pointer comparison?).

Anyway, we should not decide to include something in spec because it
can/cannot be implemented. And this proposal can make additional
possibility to js libraries.

For example, facebook/ImmutableJS currently uses array-based O(n) approach
for it's Map/Set structure. Because there's still no way to compare
arbitrary objects in js. Yes, O(n) for search!

2016. 9. 19. 오후 6:44에 "Michał Wadas" <michalwadas at gmail.com>님이 작성:

> If you call such implementation million times per second, you would need
> ~280 years to exhaust 2^53 values. So it's definitely a long running
> program.
>
> On 19 Sep 2016 11:28 a.m., "Park Hyeonu" <nemo1275 at gmail.com> wrote:
>
>> I'm definitely not a js engine expert but isn't there some
>> pointer-of-pointer thingy that points rearranged position(maybe called
>> handle)?
>>
>> I leaved the exact comparing rule as black box and let engines care such
>> cases. The single rule is that it should be deterministic.
>>
>> Anyway, your WeakMap-based implementation can easily exceeds
>> Number.MAX_SAFE_INTEGER with some long-running application, as numbers
>> cannot be reused.
>>
>> 2016. 9. 19. 오후 6:03에 "Michał Wadas" <michalwadas at gmail.com>님이 작성:
>>
>>>
>>> On Mon, Sep 19, 2016 at 7:32 AM, Park Hyeonu <nemo1275 at gmail.com> wrote:
>>>
>>>> I'm sure this feature is already implemented for every modern js
>>>> engines, as it's needed to implement Map/Set.
>>>>
>>>
>>> But you know that, it's indeterministic and implementation is free to
>>> reorganize pointers?
>>>
>>> a = {}; b = {};
>>> Object.compare(a,b); // 1
>>> gc.enforceGC();
>>> Object.compare(a,b); // -1
>>>
>>> So any userland structure can't rely on persistence of order.
>>>
>>> Moreover, such ordering can be implemented with WeakMap.
>>>
>>> const wm = new WeakMap()
>>> let i = 0;
>>> function getId(obj) {
>>>     if (!wm.has(obj))
>>>         wm.set(obj, i++);
>>>     return wm.get(obj);
>>> }
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160919/995cdc09/attachment-0002.html>


More information about the es-discuss mailing list