Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#5200 closed defect (fixed)

AIInterface freezes the game for 8 seconds on gamestart

Reported by: elexis Owned by:
Priority: Must Have Milestone: Alpha 23
Component: UI & Simulation Keywords:
Cc: Patch: Phab:D1559

Description

There is an about 8 second freeze on the loading screen before the mapgen starts.

It occurs when simulation/helpers/Setup.js initializes the diplomacy with SetTeam. That broadcasts MT_DiplomacyChanged which triggers Auras.prototype.Clean().

According to temple, AIInterface.prototype.OnTemplateModification consumes most of the time for processing that.

See Phab:P127 for some statistics in seconds. It's only teambonuses that change the template costs and it is slow (500ms per call) without any entities on the map.

WARNING: Auras.OnDiplomacyChanged ["teambonuses/brit_player_teambonus"] 0.667
WARNING: Auras.OnDiplomacyChanged ["teambonuses/iber_player_teambonus"] 0.697
WARNING: Auras.OnDiplomacyChanged ["teambonuses/sele_player_teambonus"] 0.792
WARNING: Auras.OnDiplomacyChanged ["teambonuses/maur_player_teambonus"] 0.917
{
	"type": "global",
	"affects": ["CitizenSoldier Javelin"],
	"affectedPlayers": ["ExclusiveMutualAlly"],
	"modifications": [
		{ "value": "Cost/Resources/food", "multiply": 0.8 },
		{ "value": "Cost/Resources/wood", "multiply": 0.8 },
		{ "value": "Cost/Resources/metal", "multiply": 0.8 },
		{ "value": "Cost/Resources/stone", "multiply": 0.8 }
	],
	"auraName": "Saripeko",
	"auraDescription": "Reduces the cost for citizen-soldier skirmishers with 20% for allies of Iberian players"
}

If this is new in Alpha 23, then it could be one of the reasons why players dropped more often in this release D1513.

Change History (10)

comment:1 by temple, 6 years ago

It's worse in a23 because of r21785, but I don't know that there's a bug in that commit. It's still unacceptably slow in a22 with lots of players on one team.

The AIInterface function takes all of the time, so we could look into making that faster. (Is the AIInterface component only used for Petra, meaning it could be disabled in games without Petra?)

comment:2 by Stan, 6 years ago

It would seem so https://github.com/0ad/0ad/search?q=AIInterface&unscoped_q=AIInterface

comment:3 by temple, 6 years ago

Patch: Phab:D1559

Actually AIInterface is disabled! But it's disabled after SetTeam, so if we just move it to before that then there's no freeze on gamestart.

Games with Petra will still have the freeze (worse with more players on the same team), so that function should be looked at.

comment:4 by elexis, 6 years ago

Milestone: BacklogAlpha 23
Priority: Nice to HaveShould Have

This freeze must have been one of the main reasons why playerdrops that were reported in #3700 before occured so much more often in alpha 23 #5163.

See also #4405 for removal of AIProxy.

Last edited 6 years ago by elexis (previous) (diff)

comment:5 by temple, 6 years ago

In 21838:

Disable AIInterface earlier to remove unnecessary lag on gamestart

Differential Revision: https://code.wildfiregames.com/D1559
Reviewed by: wraitii
Comments by: elexis, Itms, Stan
Refs: #5200

comment:6 by Stan, 6 years ago

Is this fixed ?

comment:7 by elexis, 6 years ago

Priority: Should HaveMust Have
Resolution: fixed
Status: newclosed

is.

(And I'm still unsure which review standards wraitii has. Verification and error analysis don't seem to be part of it.)

There are some larger freezes after mapgen finished, #3700 describes some of them, for instance ParseEntities can be really slow (20s). For rejoiners it seems unneeded altogether, see #5202. But there are other undocumented freezes after that too. Something to take a look at.

comment:8 by temple, 6 years ago

I had left the ticket open because there's more things to do, but as far as a23 goes it's done.

comment:9 by elexis, 6 years ago

Trying to not construct the AIInterface (AIProxy?) component in the ComponentManager rather than disabling it later.

refs #2370, #4405, likely many undocumented tasks

comment:10 by elexis, 6 years ago

In 21842:

Prevent players from disconnecting during the loading screen by increasing the timeout tolerance to 60 seconds for that period, fixes #5163.

The NetClient runs in the main thread, so any part of the loading screen consuming several seconds makes that client timeout.
This is a workaround because threading the NetClient would have prevent these timeouts, refs #3700.
Coutnerintuitively, since enet timeout tolerance is proportional to the latency, the better the connection of the player, the more likely it was to drop on gamestart.

This problem became very frequent in Alpha 23, at least due to the Aura bugfix rP21785, AIInterface being particularly slow and that not having been disabled yet in the loading screen resulting in additional 10 second freezes during the loading screen, even on empty maps, refs #5200, rP21838.

Differential Revision: https://code.wildfiregames.com/D1513
Based on patch by: causative

Note: See TracTickets for help on using tickets.