lookup optimization

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

lookup optimization

Michael Baczynski-2
I just came across this post: http://jacksondunstan.com/articles/1305 (amazing lookups optimization)
The author states that casting a value before assignment is a lot faster, e.g.:

//as3:
function test(items:Array, index:uint): void {
   var item:MyItem = items[index] as MyItem; //faster
}

I am trying to reproduce this in haXe but in my tests the numbers are exactly the same (casting is
actually 1% slower) so I'm wondering if there is something wrong my code:

var item:MyItem = Lib.as(a[i], MyItem);

Lib.as() equals 'as' keyword in AS3, right?

best,
michael

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: lookup optimization

Andy Li
the cool thing is, haxe actually auto cast the Array value ;)

cheers,
Andy

On Wed, Jul 20, 2011 at 7:08 PM, Michael Baczynski
<[hidden email]> wrote:

> I just came across this post: http://jacksondunstan.com/articles/1305
> (amazing lookups optimization)
> The author states that casting a value before assignment is a lot faster,
> e.g.:
>
> //as3:
> function test(items:Array, index:uint): void {
>  var item:MyItem = items[index] as MyItem; //faster
> }
>
> I am trying to reproduce this in haXe but in my tests the numbers are
> exactly the same (casting is actually 1% slower) so I'm wondering if there
> is something wrong my code:
>
> var item:MyItem = Lib.as(a[i], MyItem);
>
> Lib.as() equals 'as' keyword in AS3, right?
>
> best,
> michael
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: lookup optimization

Achmad Aulia Noorhakim
Hmm finally somebody asking about the blog post :). I think haXe already done that automatically.

On Wed, Jul 20, 2011 at 6:10 PM, Andy Li <[hidden email]> wrote:
the cool thing is, haxe actually auto cast the Array value ;)

cheers,
Andy

On Wed, Jul 20, 2011 at 7:08 PM, Michael Baczynski
<[hidden email]> wrote:
> I just came across this post: http://jacksondunstan.com/articles/1305
> (amazing lookups optimization)
> The author states that casting a value before assignment is a lot faster,
> e.g.:
>
> //as3:
> function test(items:Array, index:uint): void {
>  var item:MyItem = items[index] as MyItem; //faster
> }
>
> I am trying to reproduce this in haXe but in my tests the numbers are
> exactly the same (casting is actually 1% slower) so I'm wondering if there
> is something wrong my code:
>
> var item:MyItem = Lib.as(a[i], MyItem);
>
> Lib.as() equals 'as' keyword in AS3, right?
>
> best,
> michael
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: lookup optimization

singmajesty
I saw this too! I figured that haXe was already making this optimization,  
but sometimes you never know until you test things.


While we are talking about "lookup optimizations," would you mind if I  
asked a question that I was wondering last night, as I was back in the  
code for Actuate?


In AS3, I used the equivalent of an object hash to store tweens for each  
object. However, the CPP target does not like using objects as a key, so I  
am reduced to using strings. I cast the object to a string, then store it  
into an array, based on string. If you have ten Sprite objects, their  
tweens will be stored together. Theoretically, this improves lookup  
performance over one huge list, but I'm not sure.


Does this sound like a good way to continue going, or should I just use  
one list, and not cast to string and store into the extra array? Fast  
lookup performance is key to fast tween performance. Or is there some  
other method I am missing?


The engine also does a fair number of Reflect calls, to inspect the  
properties of a tween, and compare to see if they should overwrite. Is  
this slow? In AS3, it is faster to loop over properties than to store them  
in a separate array, but with haXe (particularly the CPP target), I'm not  
as sure.


Does anyone have recommendations for optimizing this sort of thing,  
especially for CPP?







On Wed, 20 Jul 2011 05:00:14 -0700, Achmad Aulia Noorhakim  
<[hidden email]> wrote:

> Hmm finally somebody asking about the blog post :). I think haXe already
> done that automatically.
>
> On Wed, Jul 20, 2011 at 6:10 PM, Andy Li <[hidden email]> wrote:
>
>> the cool thing is, haxe actually auto cast the Array value ;)
>>
>> cheers,
>> Andy
>>
>> On Wed, Jul 20, 2011 at 7:08 PM, Michael Baczynski
>> <[hidden email]> wrote:
>> > I just came across this post: http://jacksondunstan.com/articles/1305
>> > (amazing lookups optimization)
>> > The author states that casting a value before assignment is a lot  
>> faster,
>> > e.g.:
>> >
>> > //as3:
>> > function test(items:Array, index:uint): void {
>> >  var item:MyItem = items[index] as MyItem; //faster
>> > }
>> >
>> > I am trying to reproduce this in haXe but in my tests the numbers are
>> > exactly the same (casting is actually 1% slower) so I'm wondering if
>> there
>> > is something wrong my code:
>> >
>> > var item:MyItem = Lib.as(a[i], MyItem);
>> >
>> > Lib.as() equals 'as' keyword in AS3, right?
>> >
>> > best,
>> > michael
>> >
>> > --
>> > haXe - an open source web programming language
>> > http://haxe.org
>> >
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>


--
Using Opera's revolutionary email client: http://www.opera.com/mail/

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: lookup optimization

Tarwin Stroh-Spijer
I thought there was an ObjectHash you can use in CPP target?


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________


On Thu, Jul 21, 2011 at 3:43 AM, Joshua Granick <[hidden email]> wrote:
I saw this too! I figured that haXe was already making this optimization, but sometimes you never know until you test things.


While we are talking about "lookup optimizations," would you mind if I asked a question that I was wondering last night, as I was back in the code for Actuate?


In AS3, I used the equivalent of an object hash to store tweens for each object. However, the CPP target does not like using objects as a key, so I am reduced to using strings. I cast the object to a string, then store it into an array, based on string. If you have ten Sprite objects, their tweens will be stored together. Theoretically, this improves lookup performance over one huge list, but I'm not sure.


Does this sound like a good way to continue going, or should I just use one list, and not cast to string and store into the extra array? Fast lookup performance is key to fast tween performance. Or is there some other method I am missing?


The engine also does a fair number of Reflect calls, to inspect the properties of a tween, and compare to see if they should overwrite. Is this slow? In AS3, it is faster to loop over properties than to store them in a separate array, but with haXe (particularly the CPP target), I'm not as sure.


Does anyone have recommendations for optimizing this sort of thing, especially for CPP?








On Wed, 20 Jul 2011 05:00:14 -0700, Achmad Aulia Noorhakim <[hidden email]> wrote:

Hmm finally somebody asking about the blog post :). I think haXe already
done that automatically.

On Wed, Jul 20, 2011 at 6:10 PM, Andy Li <[hidden email]> wrote:

the cool thing is, haxe actually auto cast the Array value ;)

cheers,
Andy

On Wed, Jul 20, 2011 at 7:08 PM, Michael Baczynski
<[hidden email]> wrote:
> I just came across this post: http://jacksondunstan.com/articles/1305
> (amazing lookups optimization)
> The author states that casting a value before assignment is a lot faster,
> e.g.:
>
> //as3:
> function test(items:Array, index:uint): void {
>  var item:MyItem = items[index] as MyItem; //faster
> }
>
> I am trying to reproduce this in haXe but in my tests the numbers are
> exactly the same (casting is actually 1% slower) so I'm wondering if
there
> is something wrong my code:
>
> var item:MyItem = Lib.as(a[i], MyItem);
>
> Lib.as() equals 'as' keyword in AS3, right?
>
> best,
> michael
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org



--
Using Opera's revolutionary email client: http://www.opera.com/mail/

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: lookup optimization

Tony Polinelli
Tarwin's talking about this: 




On Thu, Jul 21, 2011 at 1:43 PM, Tarwin Stroh-Spijer <[hidden email]> wrote:
I thought there was an ObjectHash you can use in CPP target?


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: <a href="tel:%2B61%203%208060%205321" value="+61380605321" target="_blank">+61 3 8060 5321
_______________________



On Thu, Jul 21, 2011 at 3:43 AM, Joshua Granick <[hidden email]> wrote:
I saw this too! I figured that haXe was already making this optimization, but sometimes you never know until you test things.


While we are talking about "lookup optimizations," would you mind if I asked a question that I was wondering last night, as I was back in the code for Actuate?


In AS3, I used the equivalent of an object hash to store tweens for each object. However, the CPP target does not like using objects as a key, so I am reduced to using strings. I cast the object to a string, then store it into an array, based on string. If you have ten Sprite objects, their tweens will be stored together. Theoretically, this improves lookup performance over one huge list, but I'm not sure.


Does this sound like a good way to continue going, or should I just use one list, and not cast to string and store into the extra array? Fast lookup performance is key to fast tween performance. Or is there some other method I am missing?


The engine also does a fair number of Reflect calls, to inspect the properties of a tween, and compare to see if they should overwrite. Is this slow? In AS3, it is faster to loop over properties than to store them in a separate array, but with haXe (particularly the CPP target), I'm not as sure.


Does anyone have recommendations for optimizing this sort of thing, especially for CPP?








On Wed, 20 Jul 2011 05:00:14 -0700, Achmad Aulia Noorhakim <[hidden email]> wrote:

Hmm finally somebody asking about the blog post :). I think haXe already
done that automatically.

On Wed, Jul 20, 2011 at 6:10 PM, Andy Li <[hidden email]> wrote:

the cool thing is, haxe actually auto cast the Array value ;)

cheers,
Andy

On Wed, Jul 20, 2011 at 7:08 PM, Michael Baczynski
<[hidden email]> wrote:
> I just came across this post: http://jacksondunstan.com/articles/1305
> (amazing lookups optimization)
> The author states that casting a value before assignment is a lot faster,
> e.g.:
>
> //as3:
> function test(items:Array, index:uint): void {
>  var item:MyItem = items[index] as MyItem; //faster
> }
>
> I am trying to reproduce this in haXe but in my tests the numbers are
> exactly the same (casting is actually 1% slower) so I'm wondering if
there
> is something wrong my code:
>
> var item:MyItem = Lib.as(a[i], MyItem);
>
> Lib.as() equals 'as' keyword in AS3, right?
>
> best,
> michael
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org



--
Using Opera's revolutionary email client: http://www.opera.com/mail/

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org