Performance: Lots of Time in "collisionLoop", in Six Passes?

I’m looking again at performance in my current project, and it appears that I may have a new bugbear: Collision.

Specifically, use of the new PStats shows a significant amount of time–about 12ms or so–being spent in “Show code:collisionLoop”, and specifically, most of that time being taken up by six passes.

[edit]
Ah, I forgot to attach a screenshot of the PStats flame chart. Here it is:


[/edit]

I’ve tried detaching environmental colliders associated with rooms that are not the current room, nor one of its neighbours, to no apparent effect (at least by looking at the frame-time).

(Accidentally detaching all environmental colliders did have a noticeable effect on frame-time… understandably. ^^; )

Similarly, switching from individual colliders to multiple solids within a single collider seemed to have no appreciable effect.

(Again, accidentally misplacing them did seem to have an effect–presumably as a result of their being culled away in a broad-phase sweep.)

For reference, my environmental colliders are all capsules or (occasionally) spheres, as best I recall, and I think that my character-colliders are all spheres or (occasionally) capsules. Projectiles are capsules–but the testing was performed with no projectiles present, as far as I’m aware.

The test was performed with the player sitting still in a room, with the camera likewise still. There might have been some active enemies, but they should have been likewise still, I think (due to being out of range).

Does anyone have any insight into what might be causing so much time to be spent in collision? And what are these six passes…?

Panda handles I think about 32 “from” colliders per scene graph traversal, if you have many “from” colliders that are all active at the same time, it needs to traverse the scene multiple times.

Combining the “from” solids into the same collider should be effective.

I’m not 100% sure detaching the inactive “from” solids is effective by itself, could you try removing them from the traverser instead of detaching them?

Ah, I see! Thank you for that explanation!

Hum… That seems to imply that I have somewhere between 161 and 192 “from” colliders active–which is a surprise!

To clarify, the solids that I was combining were “into” solids.

(I would have thought that doing so would at least improve performance by virtue of reducing the number of states–but perhaps there’s a counterbalancing decrease in performance elsewhere, or else the improvement is very minimal.)

Ah, that’s something that I’d thought about, but forgotten!

Hmm… A quick change to remove the main “from” colliders used by NPCs seems as though it might provide a tiny benefit–but really not much, if at all.

However, I might try a more extensive change tomorrow, removing everything added to cTrav at the least, and perhaps from some non-cTrav traversers as well. (The latter tend not to be traversed when the object that owns them isn’t active, so I’m not sure that removing the colliders would help there.)

[edit]
Looking again at the flame charts, I note that it’s cTrav specifically that seems to be the problem, so I’ll likely leave the non-cTrav traversers alone for now.
[/edit]

Let me ask further, then: Is it worth removing colliders from collision-handlers, too? Offhand, I believe that I have both a pusher and a number of queues.

[edit 2]
Okay, a more-extensive change did indeed improve things, I do believe!

Specifically, “collisionLoop” is now down to about 4ms, and one or two passes (and that’s with a number of enemies on-screen)!

Thank you so much for your help! :slight_smile:

(I’m still interested to know whether it’s worth looking at collision-handlers, as well as the collision-traverser.)

There’s probably not really going to be a big benefit from removing colliders from handlers if you’ve already removed them from the traverser.

Okay, fair enough–I’ll leave that be then, I intend!

Thank you for the answer! :slight_smile: