Lazy evaluation

Steve Fink sphink at gmail.com
Mon Sep 11 19:15:43 UTC 2017


On 9/11/17 5:36 AM, Matthew Robb wrote:
> > I think it's irrelevant if internally VMs are not too happy. VMs are 
> there to solve our problems, not vice-versa ;-)
>> This ^​ is very important for everyone to get on board with. 
> Regardless the cost should be negligible as the shape is only changing 
> at the point of delayed init. This will cause, for example V8, to deop 
> the object and have to build a new hidden class but only the one time. 
> I guess it would potentially be interesting to support an own property 
> that when undefined would delegate up the proto chain.

(I don't know, but) I would expect it to be worse than this. The shape 
is changing at the point of delayed init, which means that if an engine 
is associating the possible set of shapes with the constructor (or some 
other form of allocation site + mandatory initialization), then that 
site will produce multiple shapes. All code using such objects, if they 
ever see both shapes, will have to handle them both. Even worse, if you 
have several of these delayed init properties and you end up lazily 
initializing them in different orders (which seems relatively easy to 
do), then the internal slot offsets will vary.

You don't need to bend over backwards to make things easy for the VMs, 
but you don't want to be mean to them either. :-)

Not to mention that the observable property iteration order will vary.

On Mon, Sep 11, 2017 at 7:09 AM, Andrea Giammarchi 
<andrea.giammarchi at gmail.com <mailto:andrea.giammarchi at gmail.com>> wrote:
>
>     Hi Peter.
>
>     Unless you have a faster way to do lazy property assignment, I
>     think it's irrelevant if internally VMs are not too happy. VMs are
>     there to solve our problems, not vice-versa ;-)
>
>     Regards
>
>
>
>     On Mon, Sep 11, 2017 at 11:54 AM, peter miller
>     <fuchsia.groan at virgin.net <mailto:fuchsia.groan at virgin.net>> wrote:
>
>         Hi Andrea,
>
>             ```
>             class CaseLazy {
>               get bar() {
>                 var value = Math.random();
>                 Object.defineProperty(this, 'bar', {value});
>                 return value;
>               }
>             }
>             ```
>
>
>         Doesn't this count as redefining the shape of the object? Or
>         are the compilers fine with it?
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170911/528da8df/attachment.html>


More information about the es-discuss mailing list