0.4.8
Late Game Performance for Timberborn 1.1.2.4.
Played in a late game save of about 350 beavers: noticeably fewer lag spikes. Whether a verify session (YielderSearchVerify = true) was run against the game's own search is not known; it is still worth one if you want the new search proven on your save.
Why this version
A multiplayer session logged on both computers showed that garbage collection is no longer what limits the slower one. It needs about 77 ms of main-thread time per tick (34 ms simulation, 3 ms for the multiplayer mod's entity hash, 40 ms of "everything else" that scales with ticks) against the 85 ms a tick may take at speed 7 with the large colony speed limit removed. It runs at about 90% of what it can do, slips behind, is asked to catch up, and the frame rate collapses over the session. So this version goes after the per-tick cost: one real saving, and a measurement of the part nobody could see into.
New: a faster search for trees and plants (on by default)
Every time a lumberjack looks for a tree (and a gatherer or a farmer for a plant), the game goes through every candidate, looks up the path distance from the building for each one, and only then asks whether the plant has anything to take. For lumberjacks the candidates are every unreserved marked tree on the map, and in a late game colony most of them are still growing. It was the largest single item in the measured colony's simulation: 2.9 ms per tick, 16% of all tick time, on a fast computer.
The distance of a plant with nothing to take matters for one thing only: whether it can be reached, and only until the search has found something reachable that is grown or alive. After that it cannot change the answer, and the mod leaves its lookup out. Plants that have something to take are looked up exactly as before, in the same order, so the answer is the game's answer, not an approximation.
- The first candidate of every search is still looked up, because that lookup is also what refills the building's terrain route map after a terrain change, and that has to happen on the same tick as without the mod.
YielderSearchVerify = trueruns the game's own search as well, compares, logs any difference and uses the game's result. Worth one session before trusting it.- If anything throws, the feature switches itself off for the session and the game's own code runs.
- Marked
(simulation)out of caution: every multiplayer peer should have it the same (YielderSearchinLateGamePerformance.cfg). - A new stats line shows what it did:
YielderSearch: 640 searches for trees and plants over 1280000 candidates; 32640 distance lookups, 1247360 left out (97%); 410.0 ms in total (0.641 ms each)(illustration, not a measurement). If a session with working lumberjacks shows 0 searches, the hook did not take; please send that log.
How much it saves depends on the forest: a lot when most marked trees are growing, nothing when every marked tree is grown.
Changed: the Timing: line splits "everything else"
everything else 30.0 ms per frame = 60% (per-frame systems of the game and mods 6.0 ms, their late-update systems 9.0 ms, the rest 15.0 ms: rendering, animation and Unity itself)
The game runs its own per-frame systems, and those that mods register, from two calls. Both are now timed; what remains is Unity. This is what should say where the slower computer's 40 ms per tick goes.
Changed: adaptive garbage collection pacing never goes below the default
One session each way (0.4.6 fixed slice, 0.4.7 paced, two computers) showed no difference that could be told from noise. On the slower computer 0.4.7 pinned the slice at 1 ms because its frames are always slow, which only makes every cycle three times as long. It is now 3 ms, or 6 ms while frames are fast and 8 ms while paused. Still experimental, still off by default.
Removed: allocation figures in the stats lines
The game's runtime does not keep the per-thread counter they needed ("the counter did not move"), so they were never shown. A separate per-entity profile answered the question instead: the whole simulation is under a tenth of all allocation, and this mod's part of it about 0.3%.
What was tested, and what was not
The harness passes against the installed game's assemblies: 44 patch targets resolve (3 new), including the new check that a patch's __result matches the target's return type. The search rule is run against a model of the game's search on 4000 random forests, with unreachable, dead and destroyed plants and ties, and must give the same answer every time; a forest of 2000 marked trees with 50 grown needs 51 lookups instead of 2000; with nothing reachable, nothing is left out. The model is mine, read from the game's code; YielderSearchVerify compares against the game's real search in a running game. 0.4.7's main menu notice has not been seen yet, because the test computers already collect incrementally.
The zip is the file that was published and played as the 0.4.8 preview, so the README inside it still calls it a preview.
Install
- Close Timberborn. Delete any older
LateGamePerformancefolder, then extractLateGamePerformance-0.4.8.zipintoDocuments/Timberborn/Mods. If you keep your ownLateGamePerformance.cfg, the new keys default toYielderSearch = true,YielderSearchVerify = false. - Requires the Harmony (2.4.1+) and Mod Settings Workshop mods.
Multiplayer: every player needs this same version and the same (simulation) settings.
SHA-256 of the zip: d7cf70b2d3e1688a9384ce230c849945f43c3214dbcdaf60a97fe74acedaa192