Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved performance and reduced memory usage #1238

Merged
merged 19 commits into from
Mar 10, 2024
Merged

Improved performance and reduced memory usage #1238

merged 19 commits into from
Mar 10, 2024

Conversation

liabru
Copy link
Owner

@liabru liabru commented Aug 13, 2023

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

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
Copy link
Owner Author

liabru commented Nov 13, 2023

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

@liabru
Copy link
Owner Author

liabru commented Nov 25, 2023

@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
1 check passed
@MaxBittker
Copy link

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