nkzw-tech / athena-crisis

Athena Crisis is an Advance Wars inspired modern-retro turn-based tactical strategy game. Athena Crisis is open core technology.
https://athenacrisis.com/open-source
Other
1.37k stars 105 forks source link

[Performance] Improve the performance of `Radius.tsx` by 2x. #9

Open cpojer opened 2 months ago

cpojer commented 2 months ago

Calculating a movement, attack or vision radius is among the most computationally intensive code paths in Athena Crisis. While its performance does not affect normal gameplay, it matters massively when the AI figures out what to optimize for. This is further exacerbated by the fact that results of radius calculations cannot be cached for long, as any action executed against map state may change the radius that is returned. For example, defeating a unit that is blocking a path may make more movement and attack options available for other units in the same turn.

This task is focused on speeding up Radius.tsx by 2x or more. Given how critical the code path is, it is acceptable to make the code in this file slightly less readable (but still reasonably maintainable), and possibly also optimize some of the downstream algorithms – as long as it doesn't change the layout of MapData. It is preferred not to modify the return types given how widely they are used across the codebase, but I am open to it based on a proof-of-concept and some discussion of the trade-offs.

Guidelines

Funding

Fund with Polar

tjamesmac commented 1 month ago

Hey, I think the link to the Radius.tsx file is broken in the issue description. Is this the correct link https://github.com/nkzw-tech/athena-crisis/blob/main/athena/Radius.tsx?

cpojer commented 1 month ago

Apologies, yes that's the file. I updated the description. I'm sorry I haven't gotten around to putting the benchmark together yet, I was hoping to use Vitest's benchmarking and using a large map with many units and calculating moveable radius over and over again for every unit.