Fix 7e1e275: Measure AI Collect Garbage performance (#9924)

This commit is contained in:
SamuXarick 2023-01-28 19:18:28 +00:00 committed by GitHub
parent 4a58d197ee
commit df89c34e03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -82,18 +82,16 @@
PerformanceMeasurer framerate((PerformanceElement)(PFE_AI0 + c->index));
cur_company.Change(c->index);
c->ai_instance->GameLoop();
/* Occasionally collect garbage; every 255 ticks do one company.
* Effectively collecting garbage once every two months per AI. */
if ((AI::frame_counter & 255) == 0 && (CompanyID)GB(AI::frame_counter, 8, 4) == c->index) {
c->ai_instance->CollectGarbage();
}
} else {
PerformanceMeasurer::SetInactive((PerformanceElement)(PFE_AI0 + c->index));
}
}
cur_company.Restore();
/* Occasionally collect garbage; every 255 ticks do one company.
* Effectively collecting garbage once every two months per AI. */
if ((AI::frame_counter & 255) == 0) {
CompanyID cid = (CompanyID)GB(AI::frame_counter, 8, 4);
if (Company::IsValidAiID(cid)) Company::Get(cid)->ai_instance->CollectGarbage();
}
}
/* static */ uint AI::GetTick()