Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cpojer opened this issue May 8, 2024 · 2 comments
Open

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

cpojer opened this issue May 8, 2024 · 2 comments

Comments

@cpojer
Copy link
Contributor

cpojer commented May 8, 2024

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

  • The current algorithm went through extensive testing and its behavior must not diverge. All changes must pass the full test suite.
  • More test cases may be added to ensure nothing breaks with the optimizations. It is allowed to update some snapshots if the order of the returned radius items is different, as long as it is the same.
  • The code must remain maintainable, but some trade-offs around readability close to Radius.tsx are acceptable if the performance improvements warrant it.
  • Performance improvements must be shown through the benchmark suite for calculating a radius. You can run the benchmark via pnpm vitest bench.
  • The primary focus should be on calculateRadius and movement radius. Speeding up attack or vision calculation by 2x while not speeding up movement radius calculation at all does not meet the objective of this task. However, speeding up movement radius calculation by 1.5x (for example) and speeding up attack and vision calculation by more beyond that might be worth it.

Funding

  • We're using Polar.sh to distribute funds.
  • You receive the reward once the issue is completed & confirmed by Nakazawa Tech.
Fund with Polar
@tjamesmac
Copy link

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
Copy link
Contributor Author

cpojer commented May 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants