Jump to content

do collisiongroups speed up the collision testing in your game?


valueerror
 Share

Recommended Posts

i dont know about the internals of phaser but i could imagine that using collision groups instead of letting everything collide with everything and filter the relevant infos in the begincontact event would be faster because phaser/p2 doesnt need to check everything against everything.. right or totally wrong because collisiongroups create an aditional overthead?

Link to comment
Share on other sites

i was just wondering because i am searching for everything possible to optimize my code for speed and i just don't know where to look..

 

what definitely is missing is a sticky thread called "phaser performance guide - tips and tricks" or something similar :) where we could summarize our experiences

Link to comment
Share on other sites

Its a good question and a good suggestion. But I don't have any quick answers for you sorry :/

If you really need to tune a lot, you're prob best to build discrete test cases where you can tweak only a few variables and observe the results. Once proven only then integrate into your game. You could also try digging into the guts of the p2 code or maybe check with the author Schteppe for a quick answer

Link to comment
Share on other sites

If you want to know if there is any meaningful difference, a bench mark can help:

console.time('bench-mark1');//do test case 1 N timesconsole.timeEnd('bench-mark1);console.time('bench-mark2');//do test case 2 N timesconsole.timeEnd('bench-mark2);

I usually run between 1k and 100k iterations depending on the test.  I keep the setup code in a snippet in Chrome devtools.

 

Note that you want to be sure you're test case isn't too simple.  The optimizer can kick in and take unexpected shortcuts that give readings that don't reflect what you can expect in actual usage.  If I have nothing else to do, I'll add 1 to an accumulator.

 

Also, if you want to benchmark some non-Phaser dependent, jsperf is awesome.

 

Bonus:  Here's a bunchmark of mine that had some surprising results:

var runCount = 10000000;var list = [];var temp = 0;//setupfor(var x = 0; x < runCount; x++) {    list[x] = x;}console.time('bench1');for(var x = 0; x < runCount; x++) {    temp += list[x];}console.timeEnd('bench1');temp = 0;console.time('bench2');underscore.each(list, function(item) {    temp += item;});console.timeEnd('bench2');temp = 0;console.time('bench3');lodash.each(list, function(item) {    temp += item;});console.timeEnd('bench3');temp = 0;console.time('bench4');list.forEach(function(item) {    temp += item;});console.timeEnd('bench4');

This assumes you're got both lodash and underscore assigned in noConflict tot their respective variables.

Link to comment
Share on other sites

thx ! this is an interesting way to test performance..  i will get back to this the nex time i am profiling my game :)

 

as for the collision groups..  still no answer - but - i deciced to go with collisiongroups because they are very very useful and i couldn't make out any difference in performance with our without them... same goes for impactEvents.. next time i'm going to use them because working with onBeginContact only just isn't that convenient... 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...