Search Unity

ConfigManager.appConfig.GetInt() spends a lot of time

Discussion in 'Unity Remote Config' started by MaximPP, Feb 9, 2021.

Thread Status:
Not open for further replies.
  1. MaximPP

    MaximPP

    Joined:
    Jan 26, 2019
    Posts:
    76
    Unity 2019.4, Remote Config 2.0.1, Android

    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:
    1) Test1(53ms) - 100 calls appConfig.GetInt() when the value exists
    1) Test2(162ms) - 100 calls appConfig.GetInt() when the value doesn't exist
    1) Test3(2ms) - 100 calls Dictionary<string, object>.TryGetValue() when the value exists
    1) Test4(2ms) - 100 calls Dictionary<string, object>.TryGetValue() when the value doesn't exist
     

    Attached Files:

  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    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()
     
  3. MaximPP

    MaximPP

    Joined:
    Jan 26, 2019
    Posts:
    76
    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.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    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?
     
  5. MaximPP

    MaximPP

    Joined:
    Jan 26, 2019
    Posts:
    76
    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);
    }
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    No, a static variable to avoid the call. Only make the call once.
     
    MaximPP likes this.
Thread Status:
Not open for further replies.