Question about reusing object used in Object.defineProperty

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Sep 23 16:17:19 PDT 2013


If I might, and sinve I've been using this or that for a while, I rather
find it convenient to use .value when you have other properties too instead
of writing them all the time.

That being said, for "few shots" ain't such big GC issue and actually some
engine is faster in doing this {value:value} rather than obj.value = value;
then pass the reference.

However, if you have a generic utility that would do that all the time or
many times per loop for whatever reason, the GC kicks might be painful in
lower end ARM devices and older Android 2.3 and 4.0 so in latter case you
better recycle the single object.

Slightly slower but much linear GC operations (you can test that with any
debugger by your own)

Cheers



On Mon, Sep 23, 2013 at 2:40 PM, J B <port25 at gmail.com> wrote:

> *oops:
>
> obj.value = 0;
> Object.defineProperty(this, 'foo', obj);
> obj.value = 1;
> Object.defineProperty(this, 'foo2', obj);
>
>
> On Mon, Sep 23, 2013 at 4:30 PM, J B <port25 at gmail.com> wrote:
>
>> *Would the former method help with reducing object allocation (and
>> therefore gc), or are there compiler optimizations that will automatically
>> make the latter as efficient?
>>
>>
>> On Mon, Sep 23, 2013 at 4:28 PM, J B <port25 at gmail.com> wrote:
>>
>>> var obj = {};
>>>
>>> Object.defineProperty(this, 'foo', obj.value = 0);
>>> Object.defineProperty(this, 'foo2', obj.value = 1);
>>>
>>> vs.
>>>
>>> Object.defineProperty(this, 'foo', {value:0});
>>> Object.defineProperty(this, 'foo2', {value:1});
>>>
>>>
>>> Would the former method help with reducing object allocation (and
>>> therefore gc), or are there compiler optimizations that will automatically
>>> make the former as efficient?
>>>
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130923/120a6590/attachment.html>


More information about the es-discuss mailing list