FAForever Forums
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Login

    Benchmarking time spent in beat functions, 'avatar update' is very expensive

    Scheduled Pinned Locked Moved Modding & Tools
    11 Posts 5 Posters 1.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • UvesoU
      Uveso
      last edited by

      When you test the beats from the Ui did you remove the UI beat throttling system from FAF ?
      https://github.com/FAForever/fa/blob/deploy/fafdevelop/lua/ui/game/gamemain.lua#L650

      This function is removed (destructive hook) in my AI mod.
      This is fixing the issue with odd numbers (0 income) inside the mini economic window:
      https://github.com/Uveso/AI-Uveso/blob/master/hook/lua/ui/game/gamemain.lua#L21

      So if player test this with my AI then there is no throttle flag/function.
      In case you get issues/bug reports.

      C 1 Reply Last reply Reply Quote 0
      • C
        crispweed @Uveso
        last edited by

        Ok @uveso, thanks for the heads up!

        OnBeatTimings measures separate times for throttled and non-throttled beat functions, which also requires, as you say, destructive hooking of the OnBeat() function in gamemain.lua. This then means that there's effectively a conflict between the hooking in the OnBeatTimings and AI-Uveso mods.

        (If these mods are both enabled, then I guess that, depending on the order in which hooks are applied, either the timings will all be shown as zero, or timings will be shown but the issue you were seeing with odd numbers in the mini economic window will come back.)

        It's pretty straightforward to do the same kind of timings without destructive hooking, however. This could be done by replacing the OnBeat() implementation in OnBeatTimings mod with the following:

        local originalOnBeat = OnBeat 
        function OnBeat()
            local time = CurrentTime()
            originalOnBeat()
            onBeatTimes[nextOnBeatTime] = CurrentTime() - time
            if nextOnBeatTime == table.getn(onBeatTimes) then
                nextOnBeatTime = 1
            else
                nextOnBeatTime = nextOnBeatTime + 1
            end
        end
        

        When the throttling thing is enabled, however, measuring throttled and non-throttled beat functions together makes it much harder to get a clear signal out of this kind of benchmarking, I find, since there is a kind of feedback effect where stuff taking time changes the frequency with which throttled functions are executed, which then also affects the timings...

        1 Reply Last reply Reply Quote 0
        • Dragun101D
          Dragun101
          last edited by

          What does the throttling even a thing?

          I’m a shitty 1k Global. Any balance or gameplay suggestions should be understood or taken as such.

          Project Head and current Owner/Manager of SCTA Project

          1 Reply Last reply Reply Quote 0
          • GiebmasseG
            Giebmasse Team Lead
            last edited by

            Is disabling the avatar updates in anyway noticeable in terms of reduced UI lag or otherwise improved performance?

            C 1 Reply Last reply Reply Quote 0
            • UvesoU
              Uveso
              last edited by

              @crispweed

              yes if my mods loads after yours then my mod will overwrite and delete your hook.
              In this case your mod simply don't work.

              On the other side if your mod is loading last, then everything is fine.
              The hook in my mod is only used to fix the econemy_mini window and is not needed for the functionality of my AI-mod.

              So we don't need to change the hook, just be sure that both mods are not active while testing beat functions.

              Just for info, these are the lines who did not work if the function is not called every beat:
              https://github.com/FAForever/fa/blob/deploy/fafdevelop/lua/ui/game/economy.lua#L402
              Income per second (incomeSec) is calculated on the base of simFrequency.
              In case this function is not called every beat it will produce negative numbers for income.
              Those numbers are floored to 0 (zero), thats why you see 0 for income in the eco window as user.

              C 1 Reply Last reply Reply Quote 0
              • C
                crispweed @Uveso
                last edited by

                @uveso

                If it's just about wanting to prevent your beat function from being skipped, maybe you could just change the following line:

                GameMain.AddBeatFunction(_BeatFunction, true)
                

                to

                GameMain.AddBeatFunction(_BeatFunction)
                

                The point is that the second parameter to GameMain.AddBeatFunction() says whether the beat function you are adding should be throttled, as I understand.

                And then maybe you wouldn't need to destructively hook OnBeat().

                (I haven't read all the code involved though, and I could definitely be misunderstanding the situation.)

                1 Reply Last reply Reply Quote 0
                • C
                  crispweed @Giebmasse
                  last edited by

                  @giebmasse said in Benchmarking time spent in beat functions, 'avatar update' is very expensive:

                  Is disabling the avatar updates in anyway noticeable in terms of reduced UI lag or otherwise improved performance?

                  So I've had issues with lag in the past that seemed to me to be related to beat functions taking too long. This includes an issue with the UI refusing to accept my commands, in certain situations, as well as more general problems with UI responsiveness. I'm pretty sure that reducing time in beat functions has helped a lot with this problem, for me.

                  It's going to depend on the machine you are playing on, and stuff like that, I guess. And just avatar updates by itself may not be an issue, whereas the time spent in this plus time spent in other UI mods may become an issue, depending on what kind of mods you are using..

                  1 Reply Last reply Reply Quote 0
                  • UvesoU
                    Uveso
                    last edited by

                    @crispweed

                    i am hooking the beatfunction destructive because i test the function for a gamepatch.
                    I plan to remove the beat throttling completely from the game. ( i can't see any speedimprovements here on my PC)

                    In case you have a better solution, then we can patch your code to the game.

                    Just be sure you don't throttle the eco stuff.

                    C 1 Reply Last reply Reply Quote 0
                    • C
                      crispweed @Uveso
                      last edited by

                      @uveso said in Benchmarking time spent in beat functions, 'avatar update' is very expensive:

                      @crispweed

                      i am hooking the beatfunction destructive because i test the function for a gamepatch.
                      I plan to remove the beat throttling completely from the game. ( i can't see any speedimprovements here on my PC)

                      OK.

                      Got to say I did wonder how useful this throttling actually is.

                      I mean, with the way this is setup, it seems like, as more units get created, and the game slows down, the 'throttled' functions are actually going to be run in more game ticks..

                      1 Reply Last reply Reply Quote 0
                      • Eternal-E
                        Eternal-
                        last edited by Eternal-

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post