# \[SOLVED\] Performance issue

**URL:** <https://forum.playcanvas.com/t/solved-performance-issue/13108>\
**Category:** Help & Support\
**Created:** [May 12, 2020, 8:32pm UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108 "2020-05-12T20:32:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [May 12, 2020, 8:32pm UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/1 "2020-05-12T20:32:10Z")

</div>

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:

```javascript
            // 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.

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [May 12, 2020, 8:35pm UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/2 "2020-05-12T20:35:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [May 12, 2020, 8:46pm UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/3 "2020-05-12T20:46:42Z")

</div>

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:

```javascript
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.

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [May 12, 2020, 8:52pm UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/4 "2020-05-12T20:52:22Z")

</div>

I also see this console warnings at all my projects:

```javascript
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

```

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [May 12, 2020, 9:05pm UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/5 "2020-05-12T21:05:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [May 12, 2020, 9:13pm UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/6 "2020-05-12T21:13:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [May 12, 2020, 10:29pm UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/7 "2020-05-12T22:29:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [May 13, 2020, 6:40am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/8 "2020-05-13T06:40:20Z")

</div>

Hi @Albertos,

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

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [May 13, 2020, 7:28am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/9 "2020-05-13T07:28:43Z")

</div>

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.

 ![Profiler3](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/2X/5/52fd5d9488f8eafffa43a292467fefc01bc8f585.png)

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [May 13, 2020, 7:31am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/10 "2020-05-13T07:31:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [May 13, 2020, 7:33am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/11 "2020-05-13T07:33:05Z")

</div>

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](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/2X/2/2700cf01be5c0fafe672c745c8f5b7f410204742.png)

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [May 13, 2020, 7:37am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/12 "2020-05-13T07:37:04Z")

</div>

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

 ![Profiler4](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/2X/6/67d0f1d58b7e1bd4f80ec2116ab162b388d06a9f.png)

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [May 13, 2020, 7:38am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/13 "2020-05-13T07:38:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [May 13, 2020, 7:39am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/14 "2020-05-13T07:39:12Z")

</div>

Yes, around 20 fps.

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [May 13, 2020, 7:40am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/15 "2020-05-13T07:40:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [May 13, 2020, 7:40am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/16 "2020-05-13T07:40:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [May 13, 2020, 7:41am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/17 "2020-05-13T07:41:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [May 13, 2020, 7:46am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/18 "2020-05-13T07:46:14Z")

</div>

Cannot add free users to private projects.

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [May 13, 2020, 9:03am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/19 "2020-05-13T09:03:31Z")

</div>

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.

> **[TopDown](https://playcanv.as/p/iiM81FM5/)**
>
> A WebGL application made with PlayCanvas (https://playcanvas.com)

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [May 13, 2020, 11:13am UTC](https://forum.playcanvas.com/t/solved-performance-issue/13108/20 "2020-05-13T11:13:22Z")

</div>

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):

 ![image](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/2X/2/222a2466701ae6054e12f284311ba28cbad188c7.jpeg)

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.

[Next page](https://forum.playcanvas.com/t/solved-performance-issue/13108.md?page=2)
