[SOLVED] Performance issue

I am curious when you call a device a slower device.

I tested another project and this has the same issue:

I test it with a new project and this has the same issue:

I see that also the (blue) spikes are in the new project to.

The profile of the new project in the post above had no added Ammo.js scripts.

I like to know what Other Primitives are?

Those are the lines that you render. If a curve has 30 segments, and you use lines to render it, it will draw 30 lines for a curve.

This one comes when you try to use the color’s data property directly. For example:

var blue = new pc.Color(0, 0, 1, 1);

// all of these will create a console warning:
var a = blue.data;
var opacity = blue.data[3];

Same goes for vector types, like pc.Vec3(). Generally, you do not want to access data property directly.

1 Like

We just dropped 1.27.4 with some physics fixes. Can you check performance again please to see if there is any impact please?

Hay @LeXXik, thanks for your information! I think I use 15 lines for the player so I assume that every start and end is a segment? Then I would end up at 30 like the information of the profiler.

Hay @yaustar , I can confirm that the problem has been solved! Would you like to inform me next time when a solution is being worked on? Thanks!

The work done in the physics is independent of this thread. Will was doing some refractoring of the physics code and found several issues along the way.

If you would like to keep up to date with upcoming work in the engine, I recommend watching the repo.

I mean especially when a problem is discussed on the forum. If I know that you are working on a solution, I can continue working on my game, otherwise I will be working on an issue that I cannot fix.

While I’m glad it fixed this problem, it wasn’t something that we were aiming to fix. The fact that it did was a lucky coincidence :sweat_smile: I was fully expecting you to say no as I didn’t think any of the fixes would have impacted you based on @Leonidas findings as they looked like garbage collections.

The best that I could of said was ‘There’s some physics refactoring and bug fixes going, they may or may not impact this issue’


Well, if you use 2 lines to draw a single line, then yes, “start” and “end” would be segments of a line. Otherwise no. A single straight line from point A to point B has no segments. That number 30 means you have 30 straight lines in the frame.

Maybe raycasts are also Other Primitives?

No, they shouldn’t be, since they are not visible, unless you use lines to render them. Try to reduce the lines to a single one line and see how it affects the number.

Hmm oké, I will check that later today and let you know.

Hello @LeXXik,

With only this line

this.app.renderLine(this.sensorLeftFront.getPosition(), this.sensorLeftFrontBottom.getPosition(), colorGrey);

I get 2 Other Primitives.

If I disable that line then it is 0.

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”:
However, Spector shows it as 2 lines and 0 points:

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.


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

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.