Some performance runs
Time Flies By Not released yet, see every post about itWell, as all testers know by now, the last dev build had some performance problems, especially when making a new world. Things would just... freeze for half a second, every now and then.
Sooooo... i added more stuff to the .tfb perf command so it shows how much memory each part of the mod uses and how often the game has to clean up after it, and today i think we nailed it down, mostly.
What was going on
Okay, but why would a few cave calculations freeze the whole game?
Because i was being an idiot with memory, basically.
To work out where cave moss can grow, the server looks at light and water around each chunk, and for every single chunk it made a bunch of big temporary arrays and then threw them away. Big enough that .NET puts them in a special pile for large stuff, and when that pile fills up the game does a full garbage collection, which stops everything. Server, client, you, all of it.
Now those arrays get made once and reused, same moss, way less mess (i hope).
While i was in there i also found a couple more things:
- In a new world every floor starts clean, but the mod still asked the game which room each floor block was in (that's a flood fill, not cheap), one buried ruin chunk took most of a second. Now it knows from the time alone that there's nothing to show yet and skips it.
- Chunks with nothing that gets dusty or mossy were still read block by block. Now the mod checks the chunk's block list first, most chunks are done right there.
- The first time the mod runs in a world it now waits half a minute after you join, so it doesn't pile on while the game is still generating the land, and tells you in chat when it starts and when it's done (you can turn the message off,
FirstRunMessagein the config).
The numbers
| Tested on new worlds | Before | Now |
| "Server overloaded" warnings | 4 (535–1,333 ms) | 0 |
| Full garbage collections | 10 in 77 s | 1 in 66 s |
| Server cave work, memory allocated | 414 MB | 92 MB |
| Cave water step, slowest | 1,321 ms | 28 ms |
| Cave work, slowest tick | 1,332 ms | 93 ms |
| Floor dust, building time while loading | about 4 s | 11 ms |
| Weathering overlay, per chunk | 0.64 ms | 0.15 ms |
For comparison i also made a world with no mods at all, and it had zero overload warnings too, so now we're back on par with vanilla there.
And well... i'm still polishing a couple of smaller things (the cave work now takes smaller bites per tick, so the server always has room for everything else), and that'll be in the next dev build. If you still get stutters after that, run .tfb perf and send me what it says, i'll take a look.
Help test Time Flies By
Want to beta test the mod before it's released? Leave a way to reach you and i'll get in touch as soon as there's something to test.