Skip to content

Improved performance and reduced memory usage - #1238

Merged
liabru merged 19 commits into
masterfrom
performance-2
Mar 10, 2024
Merged

Improved performance and reduced memory usage#1238
liabru merged 19 commits into
masterfrom
performance-2

Conversation

@liabru

@liabru liabru commented Aug 13, 2023

Copy link
Copy Markdown
Owner

This PR focuses on performance improvements around memory usage.

Scenes with a large number of colliding pairs will benefit most from these changes.

On the stress3, stress4 examples using the benchmark command in Node running on my Mac M1 Air:

  • improved average performance up to ~6%
  • reduced average memory usage up to ~30%
  • reduced minor and major memory GC frequency / duration
  • smoother frame rates as a result

Other examples show smaller improvements as they tend to have a much lower number of colliding pairs.

Changes

  • optimised Pairs.update
  • reduced array resizing and object disposal
  • increased object reuse and caching
  • increased local variable caching
  • changed to a more compact Pair.id format
  • changes to collision.supports as below

Migration

  • Matter.Collision use collision.supportCount instead of collision.supports.length for active supports
  • Matter.Pair use pair.contacts instead of pair.activeContacts
  • Matter.Pair use pair.contactCount instead of pair.contacts.length for active contacts
  • Pair.id format has changed

@liabru liabru changed the title Improved memory performance Improved performance and reduced memory usage Aug 13, 2023
@photonstorm

Copy link
Copy Markdown

Just to say that I merged this PR into the version of Matter I use with Phaser and it worked great in all of my tests except one: When sleeping is enabled, collisions between sleeping bodies get removed from the Pairs list too early and things start to fall through each other / the world. I noticed there was a fix for this in #1079 but it wasn't included in this PR so I think gets lost?

@liabru

liabru commented Nov 13, 2023

Copy link
Copy Markdown
Owner Author

@photonstorm thanks for taking a look - I've pushed an update re. sleeping bodies here, hopefully that covers it?

@liabru

liabru commented Nov 25, 2023

Copy link
Copy Markdown
Owner Author

@photonstorm I've just pushed a couple more changes to handle pair removal in composite removal cases, that might be the last part here so I think I'll get this merged soon but feel free to let me know if you spotted anything else on this.

* master:
  bump package lock
  improve test comparison report
  fixed compare tool layer order in demo testbed
* master:
  update ci
  update ci
* master:
  improve test comparison report
@liabru
liabru merged commit 4e6a8d9 into master Mar 10, 2024
@MaxBittker

Copy link
Copy Markdown

woot

@liabru liabru mentioned this pull request Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants