2019-04-25 02:15 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0006169Spring engineGeneralpublic2019-03-19 23:18
ReporterGoogle_Frog 
Assigned To 
PrioritynormalSeveritycrashReproducibilityhave not tried
StatusresolvedResolutionno change required 
Product Version104.0 +git 
Target VersionFixed in Version104.0 +git 
Summary0006169: 104.0.1-1085-gfc6d80e maintenance Failed to allocate memory with AI involved
Descriptionhttps://github.com/ZeroK-RTS/CrashReports/issues/20677
TagsNo tags attached.
Checked infolog.txt for lua ErrorsYes
Attached Files

-Relationships
+Relationships

-Notes

~0019867

Kloot (developer)

Last edited: 2019-03-17 18:17

View 2 revisions

[PreGame::AddGameSetupArchivesToVFS] using map: AlienDesert
[~ScopedOnceTimer][Game::LoadSkirmishAIs::CreateAI(id=0)] 68117ms

no AI should need 68 seconds to initialize normally on a map like this, may have been a runaway (failed) allocation in CircuitAI.

~0019879

lamer (reporter)

3564MB RAM, Win 7
AddressSanitizer (libasan) reported no memory leaks or corruptions inside AI.
According to my valgrind run on linux64 engine+ZK uses about 2.5~2.7GB at first 2 minutes of play (--pages-as-heap=yes shows 4.8GB, i use valgrind for the 1st time, so lets say 2.5GB), that should be significant for a system with 3564MB only.

Yet what's strange is that heaviest AI's memory allocation is coming from calling engine's CAICallback::GetUnitDefHeight to get height of a unit. It was recently added to solve water target selection. AI caches height for each possible UnitDef at the start, hence engine loads each model with all textures and whistles. How to workaround it?

Attached results of 2-minute runs.
I expected more memory usage because of per-AI threat, blocking and area maps for several types of units. Overall i see no critical issues within AI except for CAICallback::GetUnitDefHeight.

$ valgrind --tool=massif --stacks=yes ./spring test_script.txt
1player vs 1AI; 4AI vs 4AI
Map - Tundra
ZK - v1.7.3.4
spring - 104.0.1-1091-g76dfb33

~0019880

Kloot (developer)

Last edited: 2019-03-19 12:44

View 2 revisions

> AI caches height for each possible UnitDef at the start, hence engine loads each model with all textures and whistles. How to workaround it?


Implement some form of on-demand caching, i.e.

  UnitDefHeightCache::UnitDefHeightCache() {
    unitDefHeightCache.fill(-1.0f); // std::array<float, N>
  }

  float UnitDefHeightCache::Get(int unitDefID {
    float& height = unitDefHeightCache[unitDefID];

    if (height < 0.0f)
      height = callback->GetUnitDefHeight(unitDefID);

    return height;
  }

~0019882

lamer (reporter)

On-demand height initialization reduced memory usage by 500MB in above specific test case.
https://github.com/spring/CircuitAI/pull/7
Now on start game uses about 1.9GB only.

~0019883

Kloot (developer)

cool, one more for the NCR list
+Notes

-Issue History
Date Modified Username Field Change
2019-03-17 02:50 Google_Frog New Issue
2019-03-17 18:14 Kloot Note Added: 0019867
2019-03-17 18:17 Kloot Note Edited: 0019867 View Revisions
2019-03-19 08:35 lamer File Added: valgrind_massif_result.zip
2019-03-19 08:35 lamer Note Added: 0019879
2019-03-19 12:43 Kloot Note Added: 0019880
2019-03-19 12:44 Kloot Note Edited: 0019880 View Revisions
2019-03-19 22:21 lamer Note Added: 0019882
2019-03-19 23:18 Kloot Status new => resolved
2019-03-19 23:18 Kloot Resolution open => no change required
2019-03-19 23:18 Kloot Fixed in Version => 104.0 +git
2019-03-19 23:18 Kloot Note Added: 0019883
+Issue History