Optimization, Performance HELP

Get help using Construct 2

Post » Tue Feb 18, 2014 9:30 pm

Im not really sure if what you say is correct.

If i make 500 objects, and tell it to test for collision against the same object. I get 18-19 fps.

If i make 500 of another type, and test against them i get the same fps.
So could indicate that it doesn't make any difference, and it does the same amount of tests.

But my point was, that if you take that game i linked earlier, there must be something in the way they do, or handles collision detection that are different than how C2 handles it. As there are no problems in that game to have several 1000 objects interacting with each other. If its because they use some type of range to determine whether an object should do collision check with another i don't know. But I can place 500 objects on the right side of the screen, and make sure that they would never interact or even come close to the other objects, and still fps would suffer. So my guess is that "On collision" simply take one object, and test against every object that its told, regardless of the other object is even relevant for testing or not. And therefore it doesn't matter whether you test 500 objects of the same type against each other, if its different type, if these objects are even close to each other and so on.

ADDED***

Ok fooled around a bit and optimized it a little, so it can now run 5000 objects with around 30 fps, so it was quite and improvement :D

And can run 2500 objects with 60 fps.

But it seems that its correct that it just does a straight up comparison when doing collision testing.nimos1002014-02-18 21:56:22
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Tue Feb 18, 2014 9:48 pm

Chrome 32 has a performance problem that's fixed in the next version. It affects node webkit as well.

On my computer, an AMD 4400+ and Nvidia 9800gt, it runs at 60 fps in Firefox, 67 fps in IE (odd...) and 60 fps in cocoonjs on both an ipad 3 and iPhone 4S.

Not sure why your laptop is having a hard time with it, but laptops are generally a lot weaker than desktops. Thoughts about what could be causing the issue: sometimes performance on laptops is reduced by having them unplugged, you could have an 'abandoned' card that isn't getting updates for its drivers anymore, if you're not using aero you're not getting hardware acceleration for the window manager, your card could be blacklisted.

Aside from that, I'm not sure. Performance is a frustrating topic sometimes, as it seems it should be simple, but isn't. :/

@nimos100 - checking 500 objects against 500 others is 250,000 collision checks per tick. That's a lot. There are ways you can cycle through them and only check them in batches, and a lot of what's going on in that video with the moving objects doesn't actually require collisions at all.
Moderator
B
94
S
33
G
33
Posts: 3,006
Reputation: 27,749

Post » Tue Feb 18, 2014 10:00 pm

Oh well it didn't work, it just seemed like it.

@nimos100 - checking 500 objects against 500 others is 250,000 collision checks per tick. That's a lot. There are ways you can cycle through them and only check them in batches, and a lot of what's going on in that video with the moving objects doesn't actually require collisions at all.

Yeah that's the same amount i got to, but i cant seem to figure out how to do that, because it my eyes, it doesn't really make sense to check for collision if the objects are not even close to each other.

But i tried adding something that would turn collision on/off, based on distance but that doesn't work well, it completely kills it, well i can make it run with 500 objects and get around 38-45 fps, but its not smooth, but look kind of funny as i have made them change color when they turn collision on/off :D

Im not sure how they do it in that game. But since each of the objects stop when they collide with each other, there must be something that check if that's the case or not. So it would require a lot of tests, regardless of it being "true" collision detection or not.

nimos1002014-02-18 22:23:10
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Tue Feb 18, 2014 10:21 pm

@nimos100 - I checked your performance test.

[QUOTE=nimos100]I made a small program here, that basically doesn't do anything except moving some small sprites around. You get a massive performance hit.[/QUOTE]

Your capx is far away from just moving some sprites around. It's moving 650 sprites around and doing 422,500 collision checks every tick.

[QUOTE=nimos100]Which is caused by "on collision", there are added nothing to it. And you are not able to change the way this event works as its part of C2. Now in the program I have added that it should only trigger this if the speed of the sprite is above 0. Which ofc shouldn't make any difference to whether it should check for collisions or not, so removing it, makes no difference. And since the event doesn't actually do anything, it doesn't matter anyway in this test.[/QUOTE]

The event most certainly does something - the collision condition is what's slamming the CPU. Conditions take CPU time, too, and in this case it's a lot of it.

You also set up the event wrong. You have:

On sprite collision with sprite
Sprite bullet speed is > 0

This means c2 misses out on all the performance benefits because it does all the collision checks first, which is the more intensive task. The filtering happens top to bottom, so what you should have done was:

Sprite bullet speed is > 0
If sprite is overlapping sprite

Doing that gets 60 fps on my computer. Checking the bullet speed is a far, far faster operation than the collision checks, so by filtering them out first, c2 doesn't have to do any collision checks at all.

[QUOTE=nimos100]On my computer the moment I spawn 350 objects, the fps drop between 20-25 instantly. Even though these objects do absolutely nothing, except being on the screen.[/QUOTE]

I want to make sure you understand that just because the object don't appear to be doing anything, doesn't mean you're not slamming the CPU. The act of checking for collisions on them all every tick is intensive, even though there is no visible result.

[QUOTE=nimos100]So even though the computer also plays a part, the C2 engine or what to call it, will be the first thing to kill performance. Im pretty sure my computer can handle rendering 650 sprites :D[/QUOTE]

Again, this example is CPU bound, not GPU.

[QUOTE=nimos100]In order to improve performance when handling lost of objects, you would need to be able to control when and under what conditions for instant collision testing should even take place.[/QUOTE]

Which you can. You can set conditions, but they need to be BEFORE the collision check. That's why you use 'is overlapping' rather than 'on collision' so you can put conditions before it (trigger conditions have to be at the top of the condition list).Arima2014-02-18 22:29:17
Moderator
B
94
S
33
G
33
Posts: 3,006
Reputation: 27,749

Post » Tue Feb 18, 2014 10:36 pm

"Your capx is far away from just moving some sprites around. It's moving 650 sprites around and doing 422,500 collision checks every tick."

I understand what you mean, but i meant "IM" not doing anything, that i don't trigger anything for these objects, C2 does a lot of things, that's why the fps drops.

"On sprite collision with sprite
Sprite bullet speed is > 0

This means c2 misses out on all the performance benefits because it does all the collision checks first, which is the more intensive task. The filtering happens top to bottom, so what you should have done was:

Sprite bullet speed is > 0
If sprite is overlapping sprite"


You are correct about that, did a test earlier of these events, and found that the "On collision" is the one that does the biggest performance hit.

1000 objects, will reduce fps by 92.5% where the same test using overlapping, only reduce fps by 62.5%. So that could explain why you don't suffer that much when you use that.

"I want to make sure you understand that just because the object don't appear to be doing anything, doesn't mean you're not slamming the CPU. The act of checking for collisions on them all every tick is intensive, even though there is no visible result."

Yeah im aware of that :)

"Which you can. You can set conditions, but they need to be BEFORE the collision check. That's why you use 'is overlapping' rather than 'on collision' so you can put conditions before it. "

Yeah it does way better than the other. Agree.
nimos1002014-02-18 22:39:13
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Wed Feb 19, 2014 2:33 am

So i made a new version :D

And got it running better by using a distance check. So can do around 2500 objects (1250 since half of them are colliding objects) and still keep it around 30 frames.



I tried to see if i could do some kind of Quadtree collision detection that i saw on the internet, that apparently divide the screen into areas for testing. So one area doesn't test against another area and so on. but couldn't really get it to work. :( And think it should probably be implemented into C2 it self, if it should even have a chance of being possible :D

Anyway here is the new Capx, if anyone is interested:
Collision test
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Wed Feb 19, 2014 6:51 am

To make a clarification about collision checking.

C2 previously used Brute for collision. This meant every object is compared to every other object based on the collision check event.

Since a few versions ago C2 now uses Collision cells. Collision cells divide the objects into rectangle based cells. this means the objects only need to check against other objects in the same cell. This is an improvement.... unless of course that the cell size is the size of your viewport :( boooo :( that's right. The screen you see is the size of a collision cell. That means your tests of object and collisions are back to using brute force.

I've insistd that C2 should use a quadtree, but I believe the reason ashley won't is because it would require a major overhaul to many of the behaviours. So don't expect better performance if everything is on the same screen,.

Anyways. there are two reasons why the OP is having a performance problem.
1. Your GPU is black listed on the browser
2. Probably un-optimized code. I've discovered lately that certain events eat performance on an every tick use :(
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Wed Feb 19, 2014 9:42 am

I re installed and updated the laptop, things work much better, still fortunately now i know i need some "code" improvements and you guys helped me a lot. Thank you.

I am happy that it was me, and not the engine, even if the engine still needs lot of work, with tests i guess i can do whatever i need.

Now to be clear, there should be a major topic or manual article, where proper usage of events is explained and update(since some structure can destroy your real fps, even if it shows 60), because this engine is advertised like an easy tool, but in reality if you dont have background in scripting(which i have, tho it didnt help this time, i wasnt carefull), you are pretty much screwed on performance.

For example in examples you see every tick > do something, pretty much everywhere, so a new user will use that without thinking and have surprises later.

Anyway this helped a lot, and i reached a few other topics that helped too.

Thanks for your time.lwgames2014-02-19 09:43:08
Image
B
30
S
5
G
1
Posts: 125
Reputation: 3,220

Post » Wed Feb 19, 2014 12:42 pm

just like to mention that you can use on collision in a subevent, ashley comfirmed that it does work,

doing collision check every couple of ticks can be a huge save

i do this, system compare tickcount%2 = 0 (checks every 2 ticks)
subevent on collision

depending on how big and how fast your objects are you can up this number

something that could be tried to improve on this method (c2 internally)

having a collision budget, there's a timer that checks how long it takes for collisions to be checked, if more than you budget, it stops the objectloop and continue on the next tick where the loop has ended,
the way its now if you have more collision checks than you system can handle it drags down the performance just to make sure every object is checked, wich could potentially be spread over more ticks,

and further i also would like too see if splitting the actual screen in 4 or 8 could improve performance
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Wed Feb 19, 2014 12:59 pm

Small update on my performance, bit of a PICNIC!

My graphics driver was out of date - updating it locks me at 60
B
59
S
21
G
9
Posts: 641
Reputation: 9,787

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: dop2000, elafreat, facecrime and 13 guests