nathanhoad / godot_dialogue_manager

A powerful nonlinear dialogue system for Godot
MIT License
2.04k stars 161 forks source link

Use cache when checking for state methods #619

Closed DanielSnd closed 1 month ago

DanielSnd commented 1 month ago

When profiling my game I found a big spike when initializing a dialogue that came from an anonymous lambda being called 500+ times in one frame.

I traced this back to the resolve_thing_method() function in DialogueManager. It uses a filter on a get_method_list array to find the method with the correct name. It seems that can get slow when done for a lot of different methods, so I made a new method that caches the needed information to a dictionary the first time it runs, and uses the cached information in subsequent calls if it's already cached or adds to the cache if it isn't.

This change greatly alleviated the big lag spike I was experiencing.

Screenshot 2024-07-17 at 10 49 37 AM

No tests failed, and no change is needed to the documentation.