Page MenuHomeWildfire Games

Speed up AI computation by not using structured clones
ClosedPublic

Authored by wraitii on May 30 2023, 6:08 PM.

Details

Summary

Following the AI unthreading in rP26274 / D3769, we can actually stop using structured clones to pass the gamestate around. This is much, much faster. On a simple AI 1v1, I get around a 15% raw speed boost. This will go down as we add more AIs, but overall it's a great change.

Further side-effects: writing clones allocated a ton of temporary data, so this probably helps significantly with memory fragmentation.

Further work: we probably don't need to reset everything every turn, which would help the GC.

Test Plan

Test that AI games still work properly. Measure the difference in speed.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

wraitii created this revision.May 30 2023, 6:08 PM

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/8102/display/redirect

Build failure - The Moirai have given mortals hearts that can endure.

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/7011/display/redirect

wraitii published this revision for review.May 30 2023, 7:28 PM
marder added a subscriber: marder.May 31 2023, 8:17 AM

Quick profile on an AI 2v2 on a Very Large Mainland map:

Shows that we gain about 1-2ms per frame, which can be up to 10%, and that we do fewer GCs.

This revision was not accepted when it landed; it landed in state Needs Review.Jun 14 2023, 9:32 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.