[SOLVED] Performance issue

I am trying to rebuild my game to fix any errors I have made. I started with all player movements, but now I have a performance problem. I’m sure the problem is in my project, but I just can’t find what is causing it.

If I move my player with this:

            // Move forward
            if (playerIsCrouching) {
                this.entity.translateLocal(0, 0, -1 * dt);
            }
            else if (playerIsWalking) {
                this.entity.translateLocal(0, 0, -2 * dt);
            }
            
            else if (playerIsRunning) {
                this.entity.translateLocal(0, 0, -4 * dt);
            }

The player moves not smooth anymore. If I move it without delta time it moves a lot of smoother. What can cause this?

Note: In other projects I sometimes experience a hitch. I think this is not because of me, but otherwise I would like to fix this too.

Where is dt coming from? Is this in the update function? Have you tried to profile it with chrome devtools?

In the main update I call this.updateMoving(dt);
And the movement code is inside that function.

Sometimes when I restart the game it works smoothly again.

I’m not sure if the outline script can cause the problem bacause I get this error a lot of times:

playcanvas-stable.dbg.js:47993 pc.Color#data is not public API and should not be used. Access color components via their individual properties.

Can a lot of console messages cause this?
Maybe @Leonidas knows more about that.

I also see this console warnings at all my projects:

playcanvas-stable.dbg.js:392 Powered by PlayCanvas 1.27.3 9b7b74c

playcanvas-stable.dbg.js:20474 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
SoundManager @ playcanvas-stable.dbg.js:20474
Application @ playcanvas-stable.dbg.js:25614
(anonymous) @ launch.js:7391
(anonymous) @ events.js:37
Events.emit @ events.js:57
(anonymous) @ launch.js:6466

launch.js:8164 [Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
(anonymous) @ launch.js:8164
(anonymous) @ events.js:37
Events.emit @ events.js:57
(anonymous) @ launch.js:6466

messenger.js:80 messenger connected
launch.js:6515 [Violation] 'load' handler took 158ms
launch.js:11662 [Violation] 'message' handler took 173ms

Ah, yes. Lots of console errors can cause this. If you launch the game from the editor not in debug mode (remove ?debug=true from the URL), does it look smoother then?

No, don’t fix it. The strange thing is that sometimes it works smoothly so I still doubt whether it is due to my script or not. I’ll continue the investigation tomorrow.

I would start profiling it in chrome devtools to work out what could be causing the issues. The removal of dt making it smoother is a false positive as the speed of the player is no determined by frame rate.

Hi @albertos,

When the hitch happens do you see any timer spike in the profiler? Update time, render time etc.

Good morning @Leonidas !

You can see the hitch also in the profiler (after 4, 14, 24 and 34 sec).
But I don’t know how to use the information from the profiler.

That spike basically indicates that somewhere in your code you are allocating/de-allocating objects every 1-2 seconds.

Check for places you are using the new keyword or any Playcanvas clone method.

Also check the Playcanvas profiler (Alt + T), these are the timers I was referring to. May indicate at what part of your code you should be looking to:

image

I don’t use any new or clone methods right now.

When the hitch happens do you see a drop on your FPS and an increase in any of the timers there?

Yes, around 20 fps.

Which timers get increased in the profiler when that happens? Render time, update time, physics time etc.

I don’t see a timer that is changing abnormal.

Not sure then, would you like to add me to your project to take a look around? Playcanvas username: leonidas

Cannot add free users to private projects.

It seems to me that everything works smoothly on my mobile, but not on my laptop. Is that also the case with you?

To move the player click and hold from the player and drag in the direction you want to move.

Thanks in advance for testing.

Posting my findings after taking a look at @albertos game. It seems there is an FPS drop of 10-20 frames every 7-9seconds on projects involving physics, on slower devices.

I haven’t isolated this yet, but what I did is opened the Terrain from Heightmap example and simulated on chrome running on a slower device (mid-tier mobile):

Indeed the frame rate drops in intervals of 7-9 seconds.

I think that’s the hitch @albertos is experiencing, seems something coming from the Ammo.js land, but I am not sure yet.