Skip to content

Comments

Fix Territory Layer Performance#270

Merged
1brucben merged 1 commit intov0.2.3aifrom
territorylayerperf
Feb 23, 2026
Merged

Fix Territory Layer Performance#270
1brucben merged 1 commit intov0.2.3aifrom
territorylayerperf

Conversation

@1brucben
Copy link
Owner

This pull request significantly refactors the TerritoryLayer class to optimize territory rendering performance and simplify color management. The main changes include replacing the priority queue-based tile rendering with a deduplicated array-based queue, packing color values for faster rendering, and reducing per-tile color computation overhead. Additionally, it introduces new benchmarks for performance testing and removes unused imports and methods.

Rendering and performance optimizations:

  • Replaced the PriorityQueue for tile rendering with a deduplicated array-based queue (renderQueue) and a bitmap (repaintFlags) to avoid redundant repaints, improving performance and simplifying the render logic. [1] [2]
  • Introduced packed RGBA color tables (territoryPacked, borderPacked, etc.) indexed by player ID, reducing per-tile color computation and enabling direct pixel buffer writes. [1] [2] [3] [4]
  • Switched tile painting to use Uint32Array views of the image data for faster pixel updates, replacing the previous method that wrote individual color channels. [1] [2] [3]

Codebase simplification:

  • Removed unused imports (PriorityQueue, PseudoRandom) and methods (enqueueTile, per-tile color cache), and consolidated per-render-pass cached state for player highlighting and focus. [1] [2] [3] [4]
  • Updated per-render logic to cache player-related state and border/defended status, reducing redundant lookups and improving clarity. [1] [2] [3] [4]

Testing improvements:

  • Added a new performance benchmark test file TerritoryLayer.perf.test.ts with an ImageData polyfill for jsdom, enabling benchmarking of the Canvas2D-based TerritoryLayer and providing a harness for alternative implementations.

Other minor fixes:

  • Fixed a nullable access in AIPlayerExecution.ts by removing the non-null assertion for nukeHandler.

…erence

- Introduced a new performance test for the Canvas2D implementation of TerritoryLayer in `TerritoryLayer.perf.test.ts`.
- Added a benchmark harness in `territory-layer-bench-harness.ts` to facilitate performance testing of different layer implementations.
- Fixed a reference issue in `AIPlayerExecution.ts` by removing the optional chaining operator on `nukeHandler` when accessing `getEffectiveSAMRange`.
@1brucben 1brucben merged commit 39549fd into v0.2.3ai Feb 23, 2026
5 of 6 checks passed
@El-Magico777 El-Magico777 modified the milestones: v0.2.3, v0.3.0 Feb 23, 2026
@El-Magico777 El-Magico777 linked an issue Feb 23, 2026 that may be closed by this pull request
@El-Magico777 El-Magico777 added the enhancement New feature or request label Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Territory layer optimalizations

2 participants