Skip to content

TileKnowledge: Optimize GetTilesVisibleToUnit#889

Open
TomWerner wants to merge 1 commit intoDevelopmentfrom
twrner/optimize-get-tiles-visible-to-unit
Open

TileKnowledge: Optimize GetTilesVisibleToUnit#889
TomWerner wants to merge 1 commit intoDevelopmentfrom
twrner/optimize-get-tiles-visible-to-unit

Conversation

@TomWerner
Copy link
Contributor

This speeds up the time for the first 100 turns in observer mode from ~40 seconds to ~35 on my chromebook, and brings the printf benchmark from ~230 ms to ~40.

Optimizations:

  • avoid TileDirection.GetValues(typeof(TileDirection)) + a dictionary lookup and just iterate over the dictionary directly
  • use a list instead of a hashmap, and size it to hold the maximum number of tiles
  • (probably not super important) pulled out some variables so they aren't accessed repeatedly in the inner loop

This speeds up the time for the first 100 turns in observer mode from ~40 seconds to ~35 on my chromebook, and brings the printf benchmark from ~250 ms to ~40.
Copy link
Contributor

@stavrosfa stavrosfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run this and it seems to almost cut the calculation times in half from ~24ms to ~12ms on my machine, good stuff!

// tiles away. We can't see the hill that is SW+SW of us
// because we are blocked. To implement this we need to
// prevent 90 degree "turns", which we handle by ensuring
// the a+b combo is never a combination of two N/S/E/W dirs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the a+b in the documentation be updated to reflect the renaming of the variables?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants