Fix inefficient lookup for item definitions by name
When items_game.txt is parsed by the client and server, they do a LOT of item definition lookups by the name. Unfortunately, CEconItemSchema::GetItemDefinitionByName searches the list of items manually which is terribly inefficient. In fact, it's so inefficient that it added 1-2 seconds of loading time on startup! This PR resolves this by using a dictionary mapping from name to item definition, reducing the time complexity from O(N) -> O(1). This reduces loading time on startup by at least 1 second.
Profiler capture before (in milliseconds)
Profiler capture after (in milliseconds)
This also causes significant spawning lag in MvM. Every AddItem call takes around 10 ms while the rest of the spawning logic is roughly 1 ms on my system. Every robot has at leat g_szRomePromoItems_Hat and g_szRomePromoItems_Misc so that's 20 ms minimum.
I'm unsure of the performance implications but could something similar not also be applied to attributes ?
I finally tested this in MvM and here are the results
Without patch:
tf_logic_mann_vs_machine(.PEAVCBaseEntity@@) thinking for 46.81 ms!!!
With patch:
tf_logic_mann_vs_machine(.PEAVCBaseEntity@@) thinking for 34.33 ms!!!
This is without cosmetics on robots so the gain will be larger the more items they have.