<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>cocos2d for iPhone &#187; Topic: Possible performance tweak</title>
		<link>http://www.cocos2d-iphone.org/forum/topic/2895</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 01:54:39 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.cocos2d-iphone.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.cocos2d-iphone.org/forum/rss/topic/2895" rel="self" type="application/rss+xml" />

		<item>
			<title>pushkin on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-45221</link>
			<pubDate>Thu, 08 Jul 2010 08:01:12 +0000</pubDate>
			<dc:creator>pushkin</dc:creator>
			<guid isPermaLink="false">45221@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am using Cocos2D to draw in frustum mode in 3D, therefore I need to access and manipulate the quad_.bl.vertices etc. in CCSprites that are drawn using the CCSpriteSheet. </p>
<p>I have subclassed the CCSprite and overridden the updateTransform method to do this, but as stated before in fast dispatch dynamic access does not work and my approach can not be used. One solution I can think of is to override the CCSpriteSheet draw method to do a normal dynamic function call for updating the transform to its children.</p>
<p>I know that the engine is for 2D and therefore my reasons are not totally kosher, however I am of the opinion that the updateTransform method should be overridable when using CCSpriteSheet.
</p></description>
		</item>
		<item>
			<title>riq on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-19615</link>
			<pubDate>Fri, 27 Nov 2009 00:16:13 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">19615@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@CJ: thanks for the info
</p></description>
		</item>
		<item>
			<title>crmagicxxx on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-19591</link>
			<pubDate>Thu, 26 Nov 2009 19:47:16 +0000</pubDate>
			<dc:creator>crmagicxxx</dc:creator>
			<guid isPermaLink="false">19591@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Did anyone spotted this article on Cocoa with Love:</p>
<p><a href="http://cocoawithlove.com/2009/11/performance-tests-replacing-core-data.html" rel="nofollow">http://cocoawithlove.com/2009/11/performance-tests-replacing-core-data.html</a></p>
<p>I am not cocos2d code expert so I don't know how much cocos2d relies on accessor methods, but if it does, maybe this article can help gaining some speeds...
</p></description>
		</item>
		<item>
			<title>CJ on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-19573</link>
			<pubDate>Thu, 26 Nov 2009 15:10:38 +0000</pubDate>
			<dc:creator>CJ</dc:creator>
			<guid isPermaLink="false">19573@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@riq: I took some time and made a test, and my hunch was correct...<br />
If you create an implementation function from a base class and run it against a subclass it actually only calls the base class' method.</p>
<p>So, in the CocosNode example above, this won't work as expected if a subclass of CocosNode happens to override visit...<br />
<pre><code>+(void) initialize {
    visitSEL = @selector(visit);
    visitCALL = (visitIMP)[CocosNode instanceMethodForSelector:visitSEL];
}</code></pre>
<p>Because now every type of CocosNode would be called by the same visitCALL() which is actually the root CocosNode's implementation of visit.</p>
<p>To get around this, each class needs to keep a unique visitCALL.<br />
Well, ok, maybe just add the + (void) initialize{} to every subclass too and store the visitCall as a Class property (not an instance property).<br />
But, since you would still have to access the class from inside CocosNode's visit to get the visitCALL specific to each subclass of CocosNode, would this added request on each iteration outweigh the performance benefit of this whole idea?</p>
<p>This kind of thing is probably a bit safer in places like the scheduler, timer, and touch dispatcher etc...
</p></description>
		</item>
		<item>
			<title>riq on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-19530</link>
			<pubDate>Thu, 26 Nov 2009 02:56:50 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">19530@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@CJ: I don't know the answer. The patch creates the "impMethod" at class initialization time.<br />
And if the patch works as you said, then the "impMethod" should be created just before entering the loop.
</p></description>
		</item>
		<item>
			<title>CJ on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-19528</link>
			<pubDate>Thu, 26 Nov 2009 02:13:28 +0000</pubDate>
			<dc:creator>CJ</dc:creator>
			<guid isPermaLink="false">19528@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Does this properly handle subclasses?</p>
<p>for example... If you have CCSprite, but keep the impMethod and selector from CCNode's visit, and at calltime you do impMethod(aSprite...);</p>
<p>Does it call CCSprite's potentially overridden method of visit?<br />
Or does it actually call the CCSprite's super class (CCNode) implementation?
</p></description>
		</item>
		<item>
			<title>M2281 on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-18620</link>
			<pubDate>Sun, 15 Nov 2009 18:22:32 +0000</pubDate>
			<dc:creator>M2281</dc:creator>
			<guid isPermaLink="false">18620@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@riq</p>
<p>Just attached the Fast Dispatching updates to r622 - This is based on the trunk checked out at 1PM EST 10/15/2009</p>
<p>I looked at the Particle code and am not sure where Fast Dispatching could be applied, if you can give me some direction I would be happy to patch.
</p></description>
		</item>
		<item>
			<title>riq on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-18514</link>
			<pubDate>Sat, 14 Nov 2009 16:19:06 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">18514@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/3315'>m2281</a>:<br />
 Could add attach the patch in this issue ? thanks.<br />
<a href="http://code.google.com/p/cocos2d-iphone/issues/detail?id=622" rel="nofollow">http://code.google.com/p/cocos2d-iphone/issues/detail?id=622</a></p>
<p>thanks
</p></description>
		</item>
		<item>
			<title>M2281 on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-18512</link>
			<pubDate>Sat, 14 Nov 2009 15:12:16 +0000</pubDate>
			<dc:creator>M2281</dc:creator>
			<guid isPermaLink="false">18512@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@riq</p>
<p>This is tested code, for fast dispatching when method is known, keep in mind the scheduler will be different, I need to look at the code.</p>
<p>EDIT: Also just did the Timer and Scheduler, funny thing was Timer in 8.2 does already this for -tick, but scheduler calls -fire on timer without fast dispatching, I have both done if you want them. I do like the IMP, SEL, and CALL suffixes.</p>
<p>CocosNode.m<br />
<pre><code>typedef void (*visitIMP)(id, SEL);
static visitIMP visitCALL;
static SEL visitSEL;

+(void) initialize {
    visitSEL = @selector(visit);
    visitCALL = (visitIMP)[CocosNode instanceMethodForSelector:visitSEL];
}</code></pre>
<p>CocosNode.m -(void)visit</p>
<pre><code>-(void) visit
{
	if (!visible)
		return;

	glPushMatrix();

	if ( grid &#38;&#38; grid.active) {
		[grid beforeDraw];
		[self transformAncestors];
	}

	[self transform];

	for (CocosNode * child in children) {
		if ( child.zOrder &#60; 0 )
			//[child visit];
			visitCALL(child, visitSEL);
		else
			break;
	}

	[self draw];

	for (CocosNode * child in children) {
		if ( child.zOrder &#62;= 0 )
			//[child visit];
			visitCALL(child, visitSEL);
	}

	if ( grid &#38;&#38; grid.active)
		[grid afterDraw:self.camera];

	glPopMatrix();
}</code></pre></description>
		</item>
		<item>
			<title>M2281 on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-18508</link>
			<pubDate>Sat, 14 Nov 2009 14:35:41 +0000</pubDate>
			<dc:creator>M2281</dc:creator>
			<guid isPermaLink="false">18508@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@riq</p>
<p>Could you list a few of the methods you think would benefit from fast dispatching? I believe I have a nice clean way to implement and would like to test.</p>
<p>There are essentially two flavors, one where the call is known at compile time example CocosNode draw, and another where it is not, example scheduler.
</p></description>
		</item>
		<item>
			<title>M2281 on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-18507</link>
			<pubDate>Sat, 14 Nov 2009 14:04:46 +0000</pubDate>
			<dc:creator>M2281</dc:creator>
			<guid isPermaLink="false">18507@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/1842'>onedayitwillmake</a></p>
<p>Both linked lists and array enumeration could benefit, because the optimization is about calling a method. The objective-c way, uses the dispatcher which has overhead, the example above bypasses the dispatcher, so when calling the same method many times, you see a performance boost.</p>
<p>With linked list it would depend on how they are implemented, make sure you setup the call pointer outside of the loop and only execute the call inside the loop.
</p></description>
		</item>
		<item>
			<title>onedayitwillmake on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-18471</link>
			<pubDate>Sat, 14 Nov 2009 00:43:41 +0000</pubDate>
			<dc:creator>onedayitwillmake</dc:creator>
			<guid isPermaLink="false">18471@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I did read the article it's a really good one actually, good link :)</p>
<p>I was asking because in regards to a physics step - you're really letting physics engine, direct who does what when aren't you?</p>
<p>I mean I suppose I am, i run through the box2d bodies linked list, and grab the corresponding cocosnode and do something with it. I was just trying to picture what kind of usage scenario you had in mind regarding physics engine integration. </p>
<p>Me not get usage case, me dumb
</p></description>
		</item>
		<item>
			<title>M2281 on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-18462</link>
			<pubDate>Fri, 13 Nov 2009 21:58:41 +0000</pubDate>
			<dc:creator>M2281</dc:creator>
			<guid isPermaLink="false">18462@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/1842'>onedayitwillmake</a></p>
<p>This is more about bypassing the dispatcher in tight loops, however any time you are doing alot of dispatching it should help, see the referenced article.
</p></description>
		</item>
		<item>
			<title>onedayitwillmake on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-18458</link>
			<pubDate>Fri, 13 Nov 2009 21:18:12 +0000</pubDate>
			<dc:creator>onedayitwillmake</dc:creator>
			<guid isPermaLink="false">18458@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>In regards to a physics engine, is this faster than a linked list?
</p></description>
		</item>
		<item>
			<title>M2281 on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-18449</link>
			<pubDate>Fri, 13 Nov 2009 19:24:06 +0000</pubDate>
			<dc:creator>M2281</dc:creator>
			<guid isPermaLink="false">18449@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@riq</p>
<p>I will be using something very similar to this in the TouchDispatcher im working on, I kinda like setting up the C signatures ahead of time so they can be reused (I also like the syntax). If defining them as static causes a problem I will let you know.</p>
<pre><code>static void (*ccTouchBegan)(id, SEL, UITouch*, UIEvent*);</code></pre>
<p>Just tested this, and it works like a champ<br />
<pre><code>typedef void (*ccTouchBegan)(id, SEL, UITouch*, UIEvent*);</code></pre></description>
		</item>
		<item>
			<title>LongJohnnyE on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-18030</link>
			<pubDate>Tue, 10 Nov 2009 14:31:11 +0000</pubDate>
			<dc:creator>LongJohnnyE</dc:creator>
			<guid isPermaLink="false">18030@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I think this would be handy for the physics engine / cocos2d integration, since you are doing a lot of calls similar calls to many objective c objects constantly. I'm no expert though....
</p></description>
		</item>
		<item>
			<title>riq on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-18013</link>
			<pubDate>Tue, 10 Nov 2009 13:54:57 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">18013@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/3315'>m2281</a>: yes, I think that trick can be applied in some parts of the code.</p>
<p><a href="http://code.google.com/p/cocos2d-iphone/issues/detail?id=622" rel="nofollow">http://code.google.com/p/cocos2d-iphone/issues/detail?id=622</a>
</p></description>
		</item>
		<item>
			<title>Lam on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-17941</link>
			<pubDate>Tue, 10 Nov 2009 03:15:41 +0000</pubDate>
			<dc:creator>Lam</dc:creator>
			<guid isPermaLink="false">17941@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Cool stuff!<br />
It reminds me of the usefulness of good old c function pointers. :D<br />
I never thought of the benefits of using in tight loops.</p>
<p>I'm glad I caught sight of this sweet info.<br />
Thanks M2281!</p>
<p>@<a href='http://www.cocos2d-iphone.org/forum/profile/98'>edisonslabs</a><br />
That's a good question.</p>
<p>For c function pointers to work with c++ member functions you'd have to supply the correct namespace/classname of the function in question.</p>
<pre><code>void (Bar::*ptrToFunc)(int);</code></pre>
<p>Now for objective c? .... With dynamically typed references.... umm </p>
<p>*Shrugs shoulder*</p>
<p>I really should look that up =/</p>
<p>Or....</p>
<p>edisonslab and I would appreciate any answers to the question!
</p></description>
		</item>
		<item>
			<title>edisonslabs on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-17940</link>
			<pubDate>Tue, 10 Nov 2009 03:07:21 +0000</pubDate>
			<dc:creator>edisonslabs</dc:creator>
			<guid isPermaLink="false">17940@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Wow nice tip, I was wondering whether something like this existed.  </p>
<p>Though the immediate question that pops up into my mind is what happens for objects that are inherited from MyNSObject? Does it call its super class (MyNSObject)'s method, or does it call the derived class's method (if its overridden)?</p>
<p>Just finished reading the site, and seeing that the performance is comparable to just basic C is mind boggling (well I guess it should have been expected).  If your game is loop intensive, this could provide an enormous performance boost.
</p></description>
		</item>
		<item>
			<title>M2281 on "Possible performance tweak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2895#post-17875</link>
			<pubDate>Mon, 09 Nov 2009 16:17:03 +0000</pubDate>
			<dc:creator>M2281</dc:creator>
			<guid isPermaLink="false">17875@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I was researching fast enumeration, very efficient BTW, and stumbled across this article, about bypassing dispatching when making calls during enumeration. It could also apply to high frequency dispatching. You basically grab the method address and bypass dynamic dispatching.</p>
<p><a href="http://www.formconstant.net/diagrams/?p=40&#038;preview=true" rel="nofollow">http://www.formconstant.net/diagrams/?p=40&#038;preview=true</a></p>
<pre><code>void (*doSomething)(id, SEL);
SEL doSomethingSel = @selector(doSomething);
doSomething = (void (*)(id, SEL))[MyNSObject instanceMethodForSelector:doSomethingSel];

for(MyNSObject *obj in nsArray) {
   doSomething(obj, doSomethingSel);
 }</code></pre></description>
		</item>

	</channel>
</rss>

