Opened 7 years ago

Last modified 3 years ago

#4293 new enhancement

Optimize the Timer calls to Unit.Gather.Gathering in UnitAI

Reported by: wraitii Owned by:
Priority: Should Have Milestone: Backlog
Component: Simulation Keywords:
Cc: Patch:

Description

From some profiling, a rather long time is spent in Timer.js each turn and the bulk of that are gather timers. The repeated calls are rather slow, as the function in general is rather slow.

In an MP 2v2, we are talking around 7/8ms per turn here, which is not negligible. We should try to optimize this as much as possible.

Change History (4)

comment:1 by wraitii, 7 years ago

I've done some work in this branch, trying to get the lower hanging fruits out first: https://github.com/wraitii/0ad/tree/GatherOptim

The profiling can be done with https://github.com/wraitii/0ad/tree/simProfiler

Here I'm mostly removing messages from ResourceSupplyChanged to direct calls to AiProxy and StatusBars, which are the only two listening to it. We might be able to do without the "if" but that could be unsafe if we ever start doing weird stuff. That long with caching the player cheat multiplier (which is static in game for each player) allows around a 50% improvement to the running time.

comment:2 by elexis, 7 years ago

Milestone: Alpha 22Backlog

Backlogging due to lack of progress

comment:3 by Imarok, 5 years ago

Component: UI & SimulationSimulation

Move tickets to Simulation as UI & Simulation got some sub components.

comment:4 by Freagarach, 3 years ago

In 25206:

Gather using ResourceGatherer instead of UnitAI.

Moves the gathering logic from UnitAI to ResourceGatherer.
Makes it easier for modders to change gathering behaviour, e.g. letting structures gather.
Refs. #4293 by optimising a bit.

Differential revision: D2662
Comments by: @bb, @Stan, @wraitii

Note: See TracTickets for help on using tickets.