Skip to content

Comments

Attack Execution Performance Update#279

Merged
1brucben merged 2 commits intov0.3.0from
attackexecutionperf
Feb 23, 2026
Merged

Attack Execution Performance Update#279
1brucben merged 2 commits intov0.3.0from
attackexecutionperf

Conversation

@1brucben
Copy link
Owner

This pull request refactors and optimizes the attack execution logic in AttackExecution.ts, focusing on performance and code clarity. The main improvements include removing redundant null checks, hoisting invariant calculations out of loops, reducing allocations in neighbor processing, and optimizing tile conquest in GameImpl.ts. These changes collectively streamline attack processing, reduce unnecessary computations, and improve maintainability.

Attack Execution Logic Improvements:

  • Removed repeated null checks for this.attack by using non-null assertions and local variables, simplifying method logic and reducing code noise. [1] [2] [3]
  • Hoisted per-tick invariants (such as hospital multipliers and frequently accessed objects) out of the main tile-processing loop to avoid redundant calculations and improve performance.
  • Optimized neighbor processing by switching from array-based iteration to direct callback-based forEachNeighbor, eliminating intermediate allocations and improving efficiency. [1] [2]
  • Simplified terrain handling in neighbor prioritization by using the magnitude() method directly, avoiding enum switches and reducing branching.

Tile Conquest Optimization:

  • Refactored GameImpl.conquer() to use direct owner ID checks and batch-aware cache invalidation, reducing unnecessary lookups and virtual dispatches. Also added a conditional branch to avoid unnecessary fallout clearing when not needed.

@1brucben 1brucben merged commit 332d91b into v0.3.0 Feb 23, 2026
7 checks passed
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.

1 participant