Bug Issue: massive slowdown with simple physics collision detection


Pages: 1

NobodyX

  • Master Stencyler
  • *
September 18, 2018, 07:13:59 pm
Between b9904 and b9906 my game become way way slower and I had 0 clue what it could be. I finally figured out what.

I'm realizing simple physics collision detection is wayyyyyyyyy slower than it should be.

I remember a while ago (like a year and a bit ago maybe?) experiencing slowdown when a couple handfuls of actors in simple physics were being pushed into walls, I might not have posted about it at the time I can't remember.

Recently I had a suspicion the slowdown from 9904 to 9909 was something related to simple physics and I checked and noticed in the changelog it says in 9909 it was fixed so actors can detect collisions from all 4 sides at once. So I think it's not its own new bug but that my game got so slow cause whatever's bad with collisions can happen 4 times more often.



I made a test game where it creates sensor-hitbox actors that move around mostly on top of each other and on tiles (the tiles aren't necessary but they help make it a lot slower). Here's how many actors it takes for the FPS to completely tank:

(testing in windows)
b9909 windows - box2d - 380 actors
b9909 windows - simple physics - 40 actors (!!!)

b9904 windows - box2d - 380 actors
b9904 windows - simple physics - 180 actors

using flash, in simple physics 9909, it can handle around only 16 (!!) actors.



I made a second test game where the actors are more spread out and their hitboxes are 1x1 pixels and there are no tiles, so it's pretty much just checking for collisions but there aren't any actual collisions.

To get below 30 fps it takes:

b9909 windows - box2d - 2500 actors
b9909 windows - simple physics  - 700 actors

b9904 windows - box2d - 2500 actors
b9904 windows - simple physics  - 700 actors
(that both builds are the same now fits with the colliding from 4 sides now = 4 times as slow theory)
« Last Edit: September 18, 2018, 07:32:02 pm by NobodyX »


New attachment added by NobodyX - September 18, 2018, 07:14:24 pm


New attachment added by NobodyX - September 18, 2018, 07:14:38 pm


LIBERADO

  • Expert Stencyler
  • *
September 18, 2018, 07:58:22 pm
This is really a major bug.
Simple Physics should always be much faster than Box2D Physics.
« Last Edit: September 18, 2018, 07:59:54 pm by LIBERADO »


rob1221

  • Master Stencyler
  • *
October 28, 2018, 09:25:24 am
Fixed in b10051.
  • Status changed from New to Resolved
  • Issue Assigned from (none) to rob1221


Bombini

  • Subscriber - Stencyl Indie
  • *
October 29, 2018, 08:08:15 am
So far i see a huge boost in perfromance.
Good job!


NobodyX

  • Master Stencyler
  • *
November 01, 2018, 01:36:14 pm
Thanks! Checking my test game it looks like it's back to as good as b9904 but that's still much worse than using Box2D. Is that not a bug or is it going to stay that way forever?


rob1221

  • Master Stencyler
  • *
November 01, 2018, 02:28:41 pm
For constantly moving actors, simple physics seems a little worse on my end but for non moving actors, it's much better.  If I disable some box2D settings on the actor then the gap widens on the movement test though (about double box2D actors).

If I disable actor to actor collisions then both box2D and simple physics perform about the same in the movement test (1000 actors) so it looks like the actor to actor performance could be improved in simple physics.
« Last Edit: November 01, 2018, 02:45:22 pm by rob1221 »


NobodyX

  • Master Stencyler
  • *
November 01, 2018, 05:45:09 pm
So how come simple physics becomes so much slower when actors are moving vs when they're staying still? All because of trying to decide which sides are being touched? Only other thing I can think of is if it's doing the continuous collision detection thing, which I honestly forgot existed until now, I don't even know if it's even a thing at all in simple physics but if it is then that could explain why it gets so slow???

I just tried disabling the continuous collision toggle on the actor and it didn't help. I saw there's a code block for turning it off globally in the continuous collision stencylpedia article  "box2D.dynamics.B2World.m_continuousPhysics = false;" but I'm assuming that doesn't affect simple physics actors.

Oh wow you're right if I change some settings on the actor (cannot be pushed, can't rotate, no friction, no continuous collision) then in Box2D I can get way more actors in that first test game I uploaded, it starts getting slow at about 2000 for me, so simple physics can handle less than 10% as many actors when they move, that's crazy. And having them stay still makes a really really big difference in simple physics yeah. Hopefully there's an answer to why movement makes things so slow in simple physics.
« Last Edit: November 01, 2018, 05:45:39 pm by NobodyX »


rob1221

  • Master Stencyler
  • *
November 01, 2018, 06:14:12 pm
I have no idea why it's slower, and it might take a lot of time to find out.  It's a complex system developed by a single person who hasn't worked on Stencyl in a long time, so making fixes for it is difficult.


NobodyX

  • Master Stencyler
  • *
November 01, 2018, 10:19:01 pm
Gotcha.


Pages: 1

Details

  • Reported
    September 18, 2018, 07:13:59 pm
  • Updated
    November 01, 2018, 10:19:01 pm

  • View Status
    Public
  • Type
    Bug
  • Status
    Resolved
  • Priority
    Normal
  • Version
    (none)
  • Fixed in
    (none)
  • Assigned to
    rob1221
  • Category
    Engine

Tags


Attachments

* simple physics slowdown.stencyl (768.99 kB - downloaded 26 times.)
* simple physics slowdown part2.stencyl (765.33 kB - downloaded 24 times.)