Florian,

Thanks for the clear explanation, very helpful!!

Regarding "test" + "101" not being optimized yet as a symbol, that is
something I guess I should have grasped myself :( However the
explanation on the "map transition" and sample code you provided  is
something I'm sure I would not have quickly figured out myself.


regards,

Peter



On Jan 1, 3:27 pm, Florian Schneider <[email protected]> wrote:
> Thanks for your observation! On my machine I get the following results:
>
> Fast:103
> Slow:1511
> Fast:934
> Slow:1519
> Fast:933
> etc.
>
> So far I can see two performance differences with your example: Slow is
> always slower than Fast, subsequent executions of Fast are slower than the
> first execution. Here is an attempt to explain why at a high level:
>
> 1. Property access with a symbol string literal ("test101") are faster than
> using a generic key expression. ("test" + "101" is not treated as a symbol
> currently). Since each property access is optimized for the type of receiver
> and key seen, it is not a good idea to mix different types of keys at the
> same access site.
>
> 2. The store object[y] = "someValue" adds a property to object on the first
> execution. This triggers a so-called map transition internally in V8. As a
> general rule, it is not a good idea to have a store that may add a property
> inside a loop.
>
> With the following modifications below to your example I get consistently
> fast performance for the Fast case:
>
> Fast:89
> Slow:1471
> Fast:74
> Slow:1439
> Fast:74
> Slow:1437
>
> > #####################################
>
> > function loop2(y) {
> >        var len = 1000*1000*10;
> >        var object = {};
> >        var start = Date.now();
> >       * object[y] = "someValue";*
> >        while (len--) {
> >                object[y] = "someValue";
> >        }
> >        return Date.now()-start;
> > };
>
> function loop(y) {
>
> >        var len = 1000*1000*10;
> >        var object = {};
> >        var start = Date.now();
> >        while (len--) {
> >                object[y] = "someValue";
> >        }
> >        return Date.now()-start;
> > };
>
> var x = "test101"; // this is fast
>
> > var y = "test" + "101"; // this is slower ???
>
> > var tries = 10;
> > while (tries--) {
> >        console.log("Fast:" + loop2(x));
> >        console.log("Slow:" + loop(y));
> > }
>
> Hope this helps.
>
> --Florian
>
>
>
>
>
>
>
>
>
> > ####################################
>
> > regards, Peter
>
> > --
> > v8-users mailing list
> > [email protected]
> >http://groups.google.com/group/v8-users

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to