ConfigManager.appConfig.GetInt() spends a lot of time, especially if called from Update()
I have profiled on an Android device and got that appConfig.GetInt() is 15-50 times longer than Dictionary<string, object>.TryGetValue() + Convert.ToInt32().
Why so long? Do I need to manually cache the RemoteConfig values into a Dictionary in my code? Why not do it on your side?
In my screenshot you can see:
Test1(53ms) - 100 calls appConfig.GetInt() when the value exists
Test2(162ms) - 100 calls appConfig.GetInt() when the value doesn’t exist
Test3(2ms) - 100 calls Dictionary<string, object>.TryGetValue() when the value exists
Test4(2ms) - 100 calls Dictionary<string, object>.TryGetValue() when the value doesn’t exist
You should never call a network call from Update. That method is called up to hundreds of times a second. How often do you expect your values to change on your server? Typically you load these values once, at the beginning of your game, in Start() or Awake()
I thought the network is only used when I call ConfigManager.FetchConfigs(), and then the values are taken from the local storage. If it isn’t, then it’s strange. But thanks! Apparently I will have to manually cache the received data.
Correct, but not sure what you mean by “cache” but yes, you would use Remote Config to set values in your game, perhaps in a game manager script as a singleton object or in static variables. But if you are not expecting any network activity, why are you calling it repeatedly in Update() without expecting any changes?
Yes, I am not expecting network activity right now. I just use appConfig.Get() in any code that I might want to change in the future. In such methods as “GetMaximumLevel()”, “GetRewardCount()” and so on. Some of these methods may be accidentally or indirectly called in the Update(). Now I understand that I am not using RemoutConfig correctly. But at the last place of work we had just such an approach with its own implementation.
For example:
public static int GetMaxLevel()
{
return RemoteConfig.appConfig.GetInt(“lastLevel”, 80);
}