Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: [UNDER CONSIDERATION] Use of apply instead of call in Observer class  (Read 7840 times)
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« 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.
« Last Edit: February 21, 2011, 08:53:06 by puremvc » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: February 17, 2011, 09:30:39 »

Why?

-=Cliff>
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #2 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.
« Last Edit: February 19, 2011, 10:58:01 by Tek » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 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>
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #4 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().


Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: February 21, 2011, 08:47:22 »

I ran that test and my browser crashed.

-=Cliff>
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #6 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.
Logged
Pages: [1]
Print