Tips1: Optimize the use of the globalDefineAlt
Do not direct use GC.getDefineINT("XXX") in hot function, because it is very slow when it is used over 100000 times
Tips8: less use gc.getInfoTypeForString("XXX")
Tip 1 is so true. In We The People (Religion and revolutions back then) I managed to lower the AI CPU usage by 1% by caching a single call to getDefineINT. 1% may not sound like a whole lot, but I think it is considering that it was a single line of code.
I have gone all in to get rid of getDefineINT and getInfoTypeForString in We The People. What I have done is written some perl scripts, which the makefile will run prior to compiling. Those will (among other things) loop through all xml files to harvest Type tags and then build enum header files. This way if somebody adds something new to xml, next time the dll is compiled, the enum will be updated to match.
Using enum values will always be the fastest solution because the compiler will see them as ints. If you write UNIT_WARRIOR and it is 4 in the xml file (didn't check, example), then the compiler will compile like you wrote 4 in the code meaning it will skip any code to look up the value entirely.
That is if the compiler is set to hardcode. If set to dynamic (adapt to changes in xml without recompiling), it will script making global const references to variables, which are set in a cpp file, which is called once right after loading xml and then never again. This time UNIT_WARRIOR is set at startup and can be used like an enum, hence same code.
Same treatment of globalDefine(ALT).
If getInfoTypeForString is needed, I made it type specific meaning if I need a UnitClassTypes, it will loop just CvUnitClassInfos to look for a match and return the result as UnitClassTypes. No need to waste time scanning strings from multiple files and no risk of name clashes between files.
CyEnumsInterface.cpp will set up python enums. It seems like vanilla haven't discovered this, but whatever c++ value is given to the enum doesn't have to be known at compile time in c++ despite the enum name. It's perfectly fine to write a loop to provide all the types from an xml file. That is you should be aware that not all xml data has been read prior to initializing python, so there might be a problem there if you aren't careful. I can't remember what has been read at this point because I modded the read order in WTP.
Long story short: with enough modding, it is possible to add UnitTypes.UNIT_WARRIOR and all the others to python and that way completely skip the need for python using getInfoTypeForString.
One huge benefit from using enum constants rather than looking up the value from a string is that if the xml entry is removed or renamed, then the enum constant is renamed, which in turn will make the compiler fail on the line using the old name. If it's a call to getInfoTypeForString, then the compiler will have no way of knowing that it will fail. I have caught multiple bugs this way. I also recently added a script to scan the python files to see when enum types are used where it checks if the enum value exist. That too has managed to catch renamed enum values.
I'm not sure how much of this is easy to copy as I haven't tried to make it modular. However I do feel like this has considerations worth adding here.