Results 1 to 11 of 11

Thread: terminate_monitor to improve turn times?

  1. #1

    Default terminate_monitor to improve turn times?

    I've been operating under the assumption, which I've seen oft repeated in these forums, that terminating monitors as soon as possible improves performance. My understanding of how the game parses the campaign script is shaky, but it must involve saving the data in campaign_script.txt (and all the other files in the imperial_campaign folder) into the .sav save file. My assumption was that when a monitor is terminated the conditions are no longer "checked" by the game. It stands to reason that this would 1) improve performance, possibly in the form of reduced AI turn times and 2) reduce the save file size (although we would expect this to be difficult to notice since the save file size naturally increases each turn as more stuff is added to the map by the player(s) and AI).

    However, I have not been able to observe either of these effects. Turn times seem to be completely unaffected by terminating monitors implying that the game is still "checking" those events/conditions and then "checking" all the way through the monitor until getting to the terminate_monitor line and then deciding nothing needs to be done since this "box has already been ticked". I've tested this by setting up a script which terminates 788 monitors (out of 1572 in the whole file) using a yes/no event message. This has no discernible effect on AI turn times even after saving and reloading the save. However, if I delete the entire script consisting of 788 monitors from campaign_script, AI turn times are reduced dramatically by almost exactly 50%. These results imply that terminate_monitor does absolutely nothing to improve performance and so the only reason to ever use it is if the script itself demands it (for whatever reason).

    Can anyone else confirm this claim that terminate_monitor does nothing to improve performance? While we're at it, can someone link me to a thread that definitively ranks the aspects of the game's data which have the greatest effect on AI turn times? I've seen some old threads where Germanicu5 and others claim AI scripts have a bigger effect than campaign_script and a few threads that claim the opposite. Campaign scripts certainly appear to have a dramatic effect on AI turn times from my own tests.

  2. #2
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: terminate_monitor to improve turn times?

    It's a numbers game - you will see a difference with high numbers of initial monitors. Take the vanilla script - turn time simply breezes by with only 35 monitors.
    Now take EBII - 916 monitors and roughly 30 seconds.

    In EBII this number is reduced over time with terminating of monitors, a decrease in turn times however is barely noticeable as it is a) gradually and b) off set by an increase on characters on the map (themselves increasing the number of times character based monitors fire).

    The worst offenders are condition monitors - they 'fire' multiple times per second all the time as long as they are 'live'.


    A simple test would be to take a script like EBII's and then terminate all monitors after a number of turns - that should establish the difference. My bet: from the 30 seconds to zero. Adding this simple code snippet under each monitor_event\condition line will do the job after the first turn, zero being the game start turn and 1 the first end turn:
    Code:
            if I_TurnNumber > 1
                terminate_monitor
            end_if
    Summary: while terminating monitors does have a positive effect on turn time length it may be off set by other factors. Best example is a comparison between a 'CharacterTurnEnd' and a SettlementTurnEnd' monitor. While settlements are finite (199 max) the number of characters after some time will by far outstrip that number. 'FactionTurn' monitors have the least impact with 31 max. Which means while terminating a 'FactionTurn' monitor will have close to zero impact on turn times doing that with a 'CharacterTurnEnd' monitor can be noticeable, especially in later stages of the game. In the end it's a cumulative and proportional affair, closing 30 monitors in EBII will have no effect most likely whereas in the base game it will make turn times nearly non existent. Closing 'condition' monitors has by far the greatest impact on turn times due to the continious triggering of it several times per second (20 times I think?)

    I am not familiar with AI scripting but I would imagine that a similar principle applies to it. In the end it's a matter of how a script is structured, again an example: there is a finance balancing script that actually works but is not practical as it causes a turn time delay of nearly a minute due to it's use and nature (the 'condition' I mentioned) of monitors.
    Last edited by Gigantus; October 05, 2020 at 11:00 PM.










  3. #3
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: terminate_monitor to improve turn times?

    Quote Originally Posted by Callistonian View Post
    My assumption was that when a monitor is terminated ... this would ... 2) reduce the save file size
    Campaign script is saved in the save file, true, but I've never read anything to suggest that a terminated monitor is removed from the save file. I suspect that internally the game simply keeps track of which monitors have been terminated so it knows which ones to ignore (not trigger) when events happen.

    Do terminated monitors still evaluate their conditions when events happen? I assume not but have no evidence to back that up. One way to find out might be a trace log. I don't have the game installed at the moment so can't try it but ... if a trace log includes a log line for a monitor firing (something like "FactionTurnStart in campaign_script.txt line 50 fired") then try terminating that line 50 monitor and see if it still appears in the log. If it doesn't then it's a safe bet that the monitor is entirely shut down, no longer testing its conditions. One would hope that a terminated monitor does not continue to test its conditions; it would be doing so for no reason as, we know, a terminated monitor does not execute any of the commands in its body.

  4. #4

    Default Re: terminate_monitor to improve turn times?

    Well, don't I look like quite the fool? My test was flawed because although my yes/no event set an event counter which would induce the 788 monitors to terminate, the monitors themselves would still need to fire (according to their own conditions) before they could terminate. I.e. none of them were actually terminated by my yes/no event so the test is completely invalid.

    Quote Originally Posted by Gigantus View Post
    Summary: while terminating monitors does have a positive effect on turn time length it may be off set by other factors.
    This is correct. I added 16,384 monitors which can be terminated with a shortcut and the difference in turn times is night and day. There can be no doubt.

    Quote Originally Posted by Withwnar View Post
    Do terminated monitors still evaluate their conditions when events happen?
    As soon as the monitor is terminated, all traces of it stop showing up in the log.
    Last edited by Callistonian; October 06, 2020 at 08:04 AM.

  5. #5
    bitterhowl's Avatar Campidoctor
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    1,695

    Default Re: terminate_monitor to improve turn times?

    We have a good thread about "optimization" somewhere around twc.

    My sister, do you still recall the blue Hasan and Khalkhin-Gol?
    Russian warship is winning. Proofs needed? Go find yourself!

  6. #6
    bitterhowl's Avatar Campidoctor
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    1,695

    Default Re: terminate_monitor to improve turn times?


    My sister, do you still recall the blue Hasan and Khalkhin-Gol?
    Russian warship is winning. Proofs needed? Go find yourself!

  7. #7
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: terminate_monitor to improve turn times?

    Quote Originally Posted by Callistonian View Post
    I added 16,384 monitors which can be terminated with a shortcut and the difference in turn times is night and day. There can be no doubt.
    Thanks for testing and confirming.

  8. #8
    Jurand of Cracow's Avatar History and gameplay!
    Join Date
    Oct 2012
    Location
    Cracovia
    Posts
    8,488

    Default Re: terminate_monitor to improve turn times?

    It's very fortunate this thread has just been running for I had a similar question.
    I think a list of "Scripting best practices" would be useful for the less experienced .
    Mod leader of the SSHIP: traits, ancillaries, scripts, buildings, geography, economy.
    ..............................................................................................................................................................................
    If you want to play a historical mod in the medieval setting the best are:
    Stainless Steel Historical Improvement Project and Broken Crescent.
    Recently, Tsardoms and TGC look also very good. Read my opinions on the other mods here.
    ..............................................................................................................................................................................
    Reviews of the mods (all made in 2018): SSHIP, Wrath of the Norsemen, Broken Crescent.
    Follow home rules for playing a game without exploiting the M2TW engine deficiencies.
    Hints for Medieval 2 moders: forts, merchants, AT-NGB bug, trade fleets.
    Thrones of Britannia: review, opinion on the battles, ideas for modding. Shieldwall is promising!
    Dominant strategy in Rome2, Attila, ToB and Troy: “Sniping groups of armies”. Still there, alas!

  9. #9

    Default Re: terminate_monitor to improve turn times?

    I think it would be great to have a resource that ranks the impact of various things on AI turn times.

    AI scripts, campaign scripts, show me scripts, trait/anc triggers, faction standing triggers, etc.

    And then also the individual components of those things, for example: monitor_conditions > monitor_events but what about 'if' blocks? How do EDCT/EDA triggers compare against monitor_events?

    This last question is relevant to what I'm working on currently because I have to use monitor_events in campaign_script if I want to add a trait/ancillary and also set an event_counter at the same time. As far as I know, you can't have any other effects (such as set_event_counter) in EDCT or EDA. But if it were possible to do everything in EDCT/EDA with triggers, would that be more efficient than using monitors?

    We already have info for script execution sequences (thanks to gsthoed), this would be complemented very nicely by info about performance for all of these things.
    Spoiler Alert, click show to read: 

    #### Start of Turn ####

    PreFactionTurnStart > CharacterTurnStart > SettlementTurnStart > FactionTurnStart

    #### End of Turn ####

    units recruited, buildings constructed, etc. > CharacterTurnEnd > SettlementTurnEnd > FactionTurnEnd

    #### Files ####

    CS > EDCT > EDA > DS

    note: triggers in EDA/EDCT can add/remove traits before they've been added in DS

  10. #10

    Default Re: terminate_monitor to improve turn times?

    Never tested whether EDCT/EDA triggers are more or less efficient than monitors, I would assume they are equal or at least similar.

    That being said EDCT/EDA triggers generally fire a lot more since they trigger.... well on characters. I noticed that especially when rebuilding our campaign (BOTET) from the ground up and was working on a pretty unpopulated map. Turn times increased pretty dramatically when populating the map with characters whereas adding new scripts often didn't have any noticeable impact at all.

    Another factor is map size, specifically region size. Unfortunately I don't have any hard data on this, but I noticed a drastic decrease in turn times on a smaller map. My guess is that AI/pathfinding decisions are faster.

  11. #11
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: terminate_monitor to improve turn times?

    IF blocks have no impact - I wrote a 220K (yes, 220.000) lines script for EBII that has literally thousands of those but only consists of about 40 monitor_events entries. The removal of the complete script part has no perceptible impact on performance.
    Turn times increased pretty dramatically when populating the map with characters whereas adding new scripts often didn't have any noticeable impact at all.
    That's what I was referring to earlier in the summary part. There is also no 'grading' of monitors (other then events versus conditions) - it's a matter of what it tests, eg how often that will be. The mentioned 'CharacterTurn' events are a prime example whose impact depends on how many characters are in play. EDA\EDCT triggers and other scripts work in exactly the same way, 'CharacterTurn' based triggers are actually not that many in either EDA or EDCT.










Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •