collinhover/impactplusplus

Most common performance issues?

Closed this issue · 9 comments

Hi there @collinhover,

i was wondering if you could tell me what the most common performance issues are with impact++? Which featueres should be used carefully because of their high performance cost?

I am asking because some friends of mine were having major framrate drops in firefox, while playing an early version of my latest impact++ game, and i am not sure where to start exactly on fixing this.

So any information or hints are greatly appreciated!

By the way, i am mainly using UI elements (text/buttons/textbubbles), persistent entities and some pathfinding.

This is a really broad question and difficult to answer. How long do the low fps times last? Is there anything specific the player is doing when these things happen? Without know any of these, my first guess would be:

Pathfinding
This might be your issue if your maps have a lot of tiles + you're allowing your pathfinding entities to search infinite distances. Complex pathfinding tries to find the shortest path to a location, but sometimes that can mean making a huge number of searches. To see what I mean, go to http://qiao.github.io/PathFinding.js/visual/ and try some searches with different collision maps. Assuming this is the issue, one way to fix this is to use the simple option in your pathfinding settings object, which makes the entities just move to the closest tile in the direction of the destination. Currently Impact++ does not precalculate most likely paths or save path searches, though both would be great for boosting performance on that front.

UI Elements
This could be an issue if you have pixel perfect drawing enabled + you're making a lot of UI elements constantly or resizing quite often. Pixel perfect drawing uses the canvas's get/setImageData methods to perform nearest neighbor scaling, and this is super hard on performance. I think the best option here is to move all drawing to the gpu through shaders, but as much as I love working with shaders, Impact++ will not use WebGL (for now).

Thank you for your detailed answer, you are awesome ;-)

I will take a closer look into pathfinding and my UI elements considering your information. The longest fps drop i know of lasts for about 3 minutes. Coincidentally this was recorded (a friend did a let's play on an early version):

http://www.youtube.com/watch?v=FCSSTfDuZrM&t=14m57s

About 14:57. The player enters a new room (a new level is loaded) and out of nowhere the FPS drops. Suddenly, after about 3-4 minutes, everything is back to normal. On this case i think this is maybe related to something that is going on with the PC of the player (something that runs in the background and is non impact++ related?).

One thing that i noticed is that, if i spawn a text bubble, the "entity counter" (from the debug panel) does not go down once the textbubble disappeared. So if i take a look at an item for about ten times, and the player yells "yes, an item!", it seems that there are 10 textbubbles in the game.

But i think this is not performance related, since nothing is actually drawn. Even if i have 100 of those "ghost text bubbles" the fps stays about 70 on my computer.

The horizontally movement of the player also seems to stutter very slightly in forefox (all the time). But because this happens even with 70 fps this may not be performance related. By the way, this behavior can be seen at my demo from issue #112.

For now i will take a closer look at the pathfinding and my UI elements. Thank you!

If it is a random spike in fps for that long and it fixes itself, I would not expect that to be caused by Impact++. More likely that is the user's computer.

As for the stuttering movement on Firefox, I can take a look at that soon.

In the case of the ghost text bubbles, this is a bad thing, even if they are not drawn. It is a bit like a memory leak, so you want to make sure to clean up things like that right away, because they will always hurt you later. My first guess is that you're forgetting to remove the text bubbles somewhere, or there is a bug in the Impact++ code. Can you look into it from your end?

I will look at the ghost bubble issue from my end. Thanks for helping!

Basically i am using the conversation entity like this:

javascript
speak: function( text ){

        var textbubble = ig.game.spawnEntity(ig.EntityConversation, 0, 0);

        textbubble.durationPerLetter = 0.05;

        textbubble.messageMoveToSettings = {
            matchPerformance: true,
            offset: {
                x: 0,
                y: -30
            },
            align: { x: 0.5,
                y: 1
            }
        };

        textbubble.addStep( text, 'player', 1);

        textbubble.activate();

    }

I don't remove the conversation manually, because the conversation entity should take care of that. 

Fun fact: The ghost textbubble only appears if a conversation is running, and get's interrupted.  So my guess is that it has something to do with deactivating interrupted conversations here:

https://github.com/collinhover/impactplusplus/blob/dev/lib/plusplus/entities/conversation.js#L447 

But to be honest, i don't really understand what the desactivate method at the trigger entity exactly does.

Removing existing conversations manually before spawning a new one like this:

``` javascript```
if( ig.game.getEntitiesByClass(ig.EntityConversation)[0] ){
  ig.game.removeEntity( ig.game.getEntitiesByClass(ig.EntityConversation)[0] );
}

... works (no more ghost textbubbles) - but this has a massive impact on the performance (at least in firefox). Sometimes to the point that the game crashes.

However, if i change this line:

https://github.com/collinhover/impactplusplus/blob/dev/lib/plusplus/entities/conversation.js#L447

To this:

javascript
ig.game.removeEntity(conversation);


It fixes the issue with the ghost textbubbles completely, without any performance issues in firefox! 

Seems to be a good solution, but i am pretty sure that you had a reason to use the`conversation.deactivate()`at that point.

Ok … thats my thoughts so far :D

Ah, when you said text bubble, I didn't realize you meant conversation entities. The reason the conversation entities don't get removed if interrupted is because they aren't complete. Triggers and conversations are designed to remain alive until triggered and completed. A conversation is not completed until it cycles through all steps, meaning a deactivate call actually resets it and the conversation is ready to reactivate. However, because you're creating conversations programmatically, you need them to despawn when they are interrupted. I think there is a setting for this in the trigger entity, but I can't check at the moment.

Sorry for the misunderstanding! I can't find a despawn-method, or settings for that, on the trigger entity. However killing the existing entity conversations before spawning a new one works for now, without any performance issues in firefox.

Which ist really weird, i don't like problems that fix themself over night. Usally this is a bad sign. Yesterday using this before spawning a new conversation:

javascript
if( ig.game.getEntitiesByClass(ig.EntityConversation)[0] ){
ig.game.removeEntity( ig.game.getEntitiesByClass(ig.EntityConversation)[0] );
}


Had an impact on the impact performance (no pun intended). Today firefox is cool with that. Strange. But for now ... no more ghost textbubble conversation entity thingys!

Not sure what i could do about the slightly stuttering on horizontally movement in firefox though ...

You're right, there is no option for what you need. You may just remove the conversation, and it will clean itself up on remove.

There is still that strange stuttering on my character in firefox, but i already moved to the next project. So as far as i am concerned we could close this issue ;-)