PureMVC Architects Lounge

PureMVC Manifold => Bug Report => Topic started by: Tekool on February 16, 2011, 10:52:41



Title: [UNDER CONSIDERATION] Use of apply instead of call in Observer class
Post by: Tekool on February 16, 2011, 10:52:41
In PureMVC standard and multicore the notifiyObserver method use :

:
this.getNotifyMethod().apply(this.getNotifyContext(),[notification]);
where

:
this.getNotifyMethod().call(this.getNotifyContext(),notification);
would be more suitable.


Title: Re: Improvement: Use of apply instead of call in Observer class
Post by: puremvc on February 17, 2011, 09:30:39
Why?

-=Cliff>


Title: Re: Improvement: Use of apply instead of call in Observer class
Post by: Tekool on February 18, 2011, 02:13:33
Because using Function.call(this, arg) is twice faster than using Function.apply(this, [arg] ).

It could be a good idea to apply this optimization on this low level class where happens most of the loops done by PureMVC when dispatching "events".

Look at here for a proof of at least what happens in JavaScript using Function.call(this, arg) instead of Function.apply(this, [arg] ) : http://jsperf.com/call-versus-apply/2/

All my JavaScript ports already use this optimization.


Title: Re: Improvement: Use of apply instead of call in Observer class
Post by: puremvc on February 20, 2011, 01:26:11
Can you point to the proof that the AS3 implementation has the same benefits and absolutely no downside?

-=Cliff>


Title: Re: [SUGGESTION] Use of apply instead of call in Observer class
Post by: Tekool on February 20, 2011, 02:34:29
A quick AS3 test : http://wonderfl.net/c/pt0W

It gives that Function.apply() is twice time slower than Function.call().




Title: Re: [SUGGESTION] Use of apply instead of call in Observer class
Post by: puremvc on February 21, 2011, 08:47:22
I ran that test and my browser crashed.

-=Cliff>


Title: Re: [UNDER CONSIDERATION] Use of apply instead of call in Observer class
Post by: Tekool on February 21, 2011, 09:53:24
Let run the test, it should take 10 seconds or more ... I will reduce the number of loops which is adapted to pass on my computer.