Why is this Phaser 3 app munching resources?

So, I’ve got a game in the pipeline.

Game environment screenshot

There’s a problem, tho. After a couple of weeks of lunch hours incrementally adding stuff, it’s regularly using up 100% of my CPU and slowing down. I don’t really know how to go about debugging what part of the application is using all those resources.

I’ve particularly noticed that if you restart the map, (by pressing r or falling in water) a few times, the resource issue gets much worse.

Possible issues:

It’s loading quite a lot of assets in /js/loader.js

The collision method on the platforms group (interaction.landOnPlatform) is being called many times a second. Although that steps over most functionality when 3 flags are false.

  landOnPlatform: function (player, platform) {     if (platform.breakable) {       interaction.breakPlatform(player, platform);     }     if (player.slamming) {       player.slamming = false;       action.shakeCamera();     }     if (player.jumping) {       if (player.body.onFloor()) {         audio.play_land();         player.jumping = false;       } else if (player.body.onCeiling()) {         audio.play_sfx('head_block')       }     }   }, 

There’s also quite a lot of objects being created by map.draw (reading a file from /maps/

Because of the repeated reloading exacerbating the issue, could it be that this block in map.draw is not removing all the objects and their interactions from memory?

  platforms.clear(true, true);   doors.clear(true, true);   water.clear(true, true);   keys.clear(true, true);   springs.clear(true, true);   sliders.clear(true, true);   slider_tracks.clear(true, true); 

The full code base is here:


I’m really looking for advice on how to find this issue, or more information on exactly what and where the issue is.

Please be kind, I’m a ruby developer playing in JavaScript, so this isn’t my first language.