Page 1 of 1

GetConversation / GetDialogueEntry Optimization Question

Posted: Tue Nov 02, 2021 8:45 pm
by VoodooDetective
I was just profiling our game and commenting out some (sometimes expensive) code we don't use (ex: DialogueSystemSceneEvents).

I've come across these two functions a few times:

DialogueDatabase:

Code: Select all

        public Conversation GetConversation(int conversationID)
        {
            return conversations.Find(c => c.id == conversationID);
        }
Conversation:

Code: Select all

        public DialogueEntry GetDialogueEntry(int dialogueEntryID)
        {
            return dialogueEntries.Find(e => string.Equals(e.id, dialogueEntryID));
        }
I was wondering if there's any reason not to have these become dictionary lookups? Like, if I cache them [ID -> Entry] and [ID -> Conversation] in two different maps, would that be problematic? Seems like it could give considerable speed up (and avoid some garbage collection) in a number of places, but I assumed there might be reason it is like it is.

Re: GetConversation / GetDialogueEntry Optimization Question

Posted: Tue Nov 02, 2021 9:10 pm
by Tony Li
It should be fine to do that. But I recommend profiling before and after. I don't know that it would give enough bang for the buck to be worth maintaining the customization.