Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Garbage from subscribing to collision events
#15
(17-12-2017, 10:56 PM)writer51 Wrote: Thanks, I appreciate it! I sent the video link to: obi@virtualmethodstudio.com

Hi Tigrero,

After watching your video and reproducing the issue, here's my conclusions:

- This only happens (to me) in very simple scenes like the one in your video, where the simulation time does not dominate the contact iteration. Once the simulation is more expensive that the contact iteration, this is not very noticeable. In more expensive scenes, the cost of iterating over contacts is shadowed by the simulation, that's why I didn't notice any performance hit.

- The culprit is ObiList's get_Item() method, which is the property getter used to access each individual contact trough the [] operator. The old code accessed the array directly, but the new one pays the price of a function call each time an element is accessed. I would however expect this to be inlined by the C# compiler and transformed into a simple array access. Why isn't this trivial optimization being done by the compiler? no idea, but the end result is that each access to the contacts array is roughly twice as expensive.

- Can this be worked around? yes, at the price of less elegant code. Instead of doing "e.contacts[i]" in CollisionEventHandler, do "e.contacts.Data[i]". This bypasses the function call and brings back the old performance. Let me know if you see the same improvement.

IMHO this is pretty ridiculous behaviour on the compiler's part. I'd like to think that once you compile the standalone version, Unity compiles with a higher optimization level enabled and inlines the call. But I have yet to test this.

let me know if this seems to improve things for you. Anyway, this shouldn't really matter except in very simple scenes, where the cost of simulation is so low that you end up profiling small things like function call costs. Remember that the impact of any given overhead on fps is much larger at high fps (over 200 fps) than at low fps. That is, the same thing that takes you from 500 to 200 fps (3ms worth of stuff), takes you from 33 to 30 fps.
Reply


Messages In This Thread
RE: Garbage from subscribing to collision events - by josemendez - 18-12-2017, 11:01 AM