Performance spike when starting a new conversation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
sebjschindler
Posts: 16
Joined: Sun Nov 17, 2019 12:07 am

Performance spike when starting a new conversation

Post by sebjschindler »

Hello, so for a while now I've noticed that when I begin speaking with someone there's a massive lag spike on interaction. Looking at the inspector, this is what I see. I am not super good at reading this, so if anyone could help me I would super appreciate it!
Capture.PNG
Capture.PNG (92.18 KiB) Viewed 1532 times
User avatar
Tony Li
Posts: 22047
Joined: Thu Jul 18, 2013 1:27 pm

Re: Performance spike when starting a new conversation

Post by Tony Li »

Hi,

The biggest sources of spikes (in descending order) are:

1. Logging to the Console / output log file. Set the Dialogue Manager's Other Settings > Debug Level to Warning. If you set it to Info, it will log dozens of lines. Each of those lines does a separate stack trace, which is very time-consuming.

2. Not ticking the Dialogue Manager's Other Settings > Preload Resources. If unticked, the Dialogue System will wait to lazy-load the dialogue UI and dialogue database until the first conversation starts, in which case it has to deserialize the assets, load them into memory, and initialize them before the conversation actually starts.

3. Canvas relayouts. When a UI element changes (such as being set active), its containing Canvas does a layout update of its entire contents. These can be especially heavy operations if you use a lot of Layout Group or Content Size Fitter components. Put each UI (dialogue UI, quest tracker HUD, quest log window, etc.) in a separate Canvas. Canvases can be nested, so you can even put Canvas components on each subtitle panel and response menu panel to further pare down the work. For simplicity, the base Dialogue Manager prefab has a single Instantiate Prefabs component that instantiates 3 UIs into the same Canvas where the Dialogue Manager also instantiates the dialogue UI. You can remove this component if you're not using those prefabs, or add more Instantiate Prefabs components so you can specify separate Canvases for each UI.

From your screenshot, I'm guessing #1 and #3.

The other possibility is if the first nodes of the conversation have Conditions or Script fields that run lengthy functions.
UrasawaX
Posts: 13
Joined: Mon Jan 27, 2020 7:52 am

Re: Performance spike when starting a new conversation

Post by UrasawaX »

Hey, first of all: great job with the Dialogue System. It's an awesome asset! Thank you very much.

But I do have the exact same problem as OP. Every time a conversation starts I get a huge performance spike. My profiler looks identical to OPs. There are over 200 calls on Mono.JIT and several thousands of GC.Alloc. Instead of ~10kb of GC allocated the profiler suddenly shows 2.0MB every time a conversation starts.

Debug Level is set to warning. Resources are preloaded. To test the canvas problem, I activated it manually before triggering the Conversation (and using one of the template UIs). The Conversation loaded is just a text without anything fancy. I deactivated all OnConversationStart events.

Nothing helps. Do you have any other ideas I could try?
User avatar
Tony Li
Posts: 22047
Joined: Thu Jul 18, 2013 1:27 pm

Re: Performance spike when starting a new conversation

Post by Tony Li »

Hi,

You can untick the Dialogue System Trigger's Skip If No Valid Entry checkbox to reduce the spike somewhat.

If you run a Deep Profile, you may see that the first time it runs a conversation (more accurately, the first time it runs a sequence), there's a spike. This is because the sequencer is initializing the list of custom sequencer commands in your project:

profile.png
profile.png (74.48 KiB) Viewed 1507 times

I'll add this initialization to the work that the Preload Resources checkbox does. In the meantime, you can significantly reduce this spike by adding a Dialogue System Trigger set to OnStart. Select Add Action > Play Sequence, and set the Sequence field to: Delay(0)

If that doesn't help, would you please send a reproduction project to tony (at) pixelcrushers.com?
UrasawaX
Posts: 13
Joined: Mon Jan 27, 2020 7:52 am

Re: Performance spike when starting a new conversation

Post by UrasawaX »

Hey Tony,
it acutally helped. Now all spikes are gone.

Thank you very much!
User avatar
Tony Li
Posts: 22047
Joined: Thu Jul 18, 2013 1:27 pm

Re: Performance spike when starting a new conversation

Post by Tony Li »

Glad to help! In the next update, I'll include that in Preload Resources so you will no longer need the extra Dialogue System Trigger.
Post Reply