Transport Fever 2

Transport Fever 2

Create your own game world!
Give your game a personal touch and change it to your liking. Create, share and install mods. Customize the game with new landscapes, vehicles, stations, assets and more.
Checking memory consumption of a mod
I've created a script mod that stores information in the state. When playing with the mod for a while I've noticed that memory utilisation slowly but surely creeps up. Is there a way of seeing how much memory the data I store actually consumes? Are there any guides on how to optimise the memory consumption?
< >
Showing 1-5 of 5 comments
I have not figured out a way of actually determining the memory consumption but I noticed that running
collectgarbage()
periodically seems to help here a lot.
Usually the Lua side is not the issue. There is api.util.getLuaUsedMemory() which you can call for each Lua state. It is about 30-100MB.

The state is stored in the engine state and passed to the Gui state frequently and also stored in the savegame file. It's size can indeed be critical, but not for the memory. Relatively "small" state size can slow down the game (CPU and probably FPS as well) because it has to go through the pipeline.

The game uses RAM (and VRAM) in many different ways, it is hard to capture and give general advice. The RAM is mostly influenced through savegame. Map size and number of elements, especially edges (streets+tracks).

Some say, the Timetable mod increases RAM consumption significantly.
Last edited by VacuumTube; 12 Jan @ 9:46am
After enabling the logging of the used memory by both the engine and the gui threads I can see that they both use around 10-12MB of memory (after garbage collection). With garbage collection running every minute I can see that the engine thread is relatively stable, freeing about 10MB every time, the gui on the other hand can sometimes release in excess of 300MB of memory which makes me think that this might be the culprit of the slow memory creep.
Originally posted by VacuumTube:

Some say, the Timetable mod increases RAM consumption significantly.

I had a look through the code of that mod and it doesn't seem to call garbage collection at all relaying on the automated process, I suspect that might be the reason. My mod was ballooning memory usage to over 50GB during a long session (swapping heavily) before I enabled garbage collection. Now it's memory usage is stable.
Wow this might explain a lot... For grins I ran api.util.getLuaUsedMemory() and collectgarbage() in a vanilla test map to see what happens and it freed up a bunch of memory. Makes me wonder how often the game cleans its own garbage, never mind the mods.

There are some other mods that might hit memory hard too. Advanced Statistics comes to mind. (I've had some performance issues with it, and the author suggested trying its flush memory option.)
< >
Showing 1-5 of 5 comments
Per page: 1530 50