[SOLVED] Performance issue

You are right. I went ahead and tried it as well, and a single line shows 2 lines for some reason. I thought perhaps those are 2 points, that compose a line. After all, points also belong to “Other primitives”:
image
However, Spector shows it as 2 lines and 0 points:
image

Not sure how to read it. Perhaps I can use my epic summoning spell to summon @mvaligursky, a lines master :slight_smile:

1 Like

Sorry to bother you with this, but I’m still having trouble moving with dt.

Because I assumed it was due to my script, I continued to search.
However, now I have created a simple object with a script with only this in the update:

// update code called every frame
MoveTest.prototype.update = function(dt) {
    this.entity.translateLocal(0, 0, -2 * dt);    
};

The object does not move smoothly!

Because it works well in another project, I really don’t know where to look for the problem anymore.

Please help!

Is the project public? If not, could you post a published build that shows this issue please?

Hello @yaustar! The project is public for now.

https://playcanvas.com/editor/scene/919052

I’ve had a quick look, and the issue is in the main update loop, which does all the updates.

// update code called every frame
Player.prototype.update = function(dt) {
    this.updateAnimation(dt);
    this.updateClimbing(dt);
    this.updateCollision(dt);
    this.updateFalling(dt);
    //this.updateInput(dt);
    this.updateJumping(dt);
    this.updateMoving(dt);
    this.updateSensors(dt);
};

First, don’t create new classes in these update functions. For example, in your updateMoving():

...
var originalRotation = new pc.Quat();
var finalRotation = new pc.Quat();

You would want to create them on initialize, instead of on every frame.

The main cause is however the updateSensors() method in your Player_Sensors.js. I counted at least 14 raycastAll() rays that you fire each frame, and then iterating over the results of each raycast. Since each raycastAll can potentially return many hits, this method can become expensive very quickly, and start tanking your CPU. Lower end phones will definitely have an FPS stutter.

I would advice to reconsider using as many raycastAll(), or even dropping them completely and using some other, less expensive ways, like trigger volumes.

2 Likes

Hello @LeXXik,

Thank you for your time and explanation! However, even when I deactivate all updates, I still don’t have a smooth movement of the cube with the test script.

As for the sensors, I just followed the advice in this post:

I deactivate everything and then this is how the cube is move on my laptop:


Specs

I’ve created a new project with only a camera in it. I also see an FPS drop with lower-end device setting (slows down CPU), even though there is nothing to render. Perhaps, @yaustar could look into it.

When is a device lower-end?

Its just a simple setting in Chrome dev tools (upper right corner):
image

The setting is relative to your computer, and it just artificially slows down your CPU by 4 or 6 times. Not really matches the real devices, but approximates the performance.

Is the FPS drop consistent up to 20-30 secs? There’s some startup stuff that takes a bit at the very beginning.

But if that were the cause then I should have a lower end device and I don’t think that’s the case.

Ah, you are right, it was only at the beginning. You can ignore it.

Well, the cube moves fine on my laptop, so I thought you were using a low-end device setting. Does your browser have hardware acceleration enabled?

(PS, sorry, seems I didn’t mute the background music…)

Where can I check the hardware acceleration?

On my mobile (iPhone X) it’s working fine to.
But my orginal build of the game that you played already is working also fine on my laptop.
So I realy don’t know where to search.

Maybe I have to start a new project again, but I like to know what causes the problem…

What resolution is your monitor or laptop display?

1920x1080 and 144hz

To be sure I removed the player entity and the player script, and the problem in this project is still there.

It’s very possible that the browser at full screen can’t render at 144Hz so it looks choppy to you. :thinking:

Try making the browser window smaller (like a quarter of the size) and see if the issue persists.

If it still does, do a performance recording in the Devtools and save the file so that we can download and take a look.

It seems that with making the screen smaller everything runs smoothly indeed! That explains why it works smoothly on my mobile.

But what I don’t understand is that I only have this problem in this project. I have another player movement project in which the player also moves smoothly on full screen…