Page 1 of 1

[boskid][2.0.28] Memory leak with overlapping poles with supply-area-distance=64

Posted: Wed Dec 25, 2024 2:35 pm
by robot256
The attached mod has only one line:

Code: Select all

data.raw["electric-pole"]["medium-electric-pole"].supply_area_distance = 64;
The attached save is vanilla plus the attached mod.

Repro steps:
1. Load the provided game with the provided mod in vanilla 2.0.28
2. Hover mouse over the combinator in the center of screen, and press R many times (on Windows 11 with 32GB or RAM, at least 20 times).
3. If the memory leak is triggered, then memory usage will start to grow with each press of R. E.g., 2GB->3.5GB->5GB->9GB->12GB->18GB. Each press will take longer to process before game execution resumes.

Info:
The combinator being rotated is powered by 4 separated power poles all drawing power from the same electric energy interface. I'm sure the memory leak is in the "which electric network am I powered by now?" code. It is also highly dependent on the exact configuration of poles and networks. Using fewer poles or poles in different locations, or just moving the poles around can cause the leak to no longer trigger.

It's also clearly in the ephemeral game state. Rotating 15 times, saving the game, and loading it again resets the effect and another 20 rotations are needed before memory-leak-induced lag happens again.

Re: [boskid][2.0.28] Memory leak with overlapping poles with supply-area-distance=64

Posted: Wed Dec 25, 2024 3:07 pm
by boskid
Thanks for the report. Issue is now fixed for 2.0.29.

All the reproduction steps, mod, save file were really helpful in quickly finding where the issue was. It happened to be an issue with one of our custom vector class that was reserving more and more memory when inserting items in the middle of a vector even when there was no need for the growth to happen. That perfectly matches with your observation about "ephemeral" state since we never save capacity of vectors and so after save-load the capacity would shrink to what is actually needed.

Re: [boskid][2.0.28] Memory leak with overlapping poles with supply-area-distance=64

Posted: Wed Dec 25, 2024 5:26 pm
by robot256
Happy to help! The repro was given to me by a friend to confirm and post. He'll be glad to have the bug fixed!