perf(core): speed up packedTileUpdates (Uint32 pairs, no tile wrappers) (#3255)

## Description
Reduces CPU + GC pressure from tile update serialization.

**What changed**
- Switched `packedTileUpdates` from `BigUint64Array` (BigInt packing) to
`Uint32Array` `[tileRef, state]` pairs, updating `GameView` ingestion.
- Updated tile state to use `GameMap.tileState(tile)` and
`GameMap.updateTile(tile, state)`.
- Removed per-tile `GameUpdateType.Tile` wrapper allocations by
recording raw `(tile, state)` pairs in `GameImpl` and draining them via
`drainPackedTileUpdates()` in `GameRunner`.

**Why it’s faster**
- Avoids BigInt and pack/unpack.
- Avoids per-tile object allocations.

**Compatibility**
- Wire format change: `packedTileUpdates` is now `Uint32Array` pairs
instead of `BigUint64Array`.

## Please complete the following:

- [ ] I have added screenshots for all UI updates
- [ ] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [ ] I have added relevant tests to the test directory
- [ ] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

DISCORD_USERNAME
This commit is contained in:
scamiv
2026-02-21 06:01:03 +01:00
committed by GitHub
parent 444aa16ac8
commit ea2a76609f
6 changed files with 68 additions and 63 deletions
+2 -12
View File
@@ -22,11 +22,7 @@ import {
import { createGame } from "./game/GameImpl";
import { TileRef } from "./game/GameMap";
import { GameMapLoader } from "./game/GameMapLoader";
import {
ErrorUpdate,
GameUpdateType,
GameUpdateViewData,
} from "./game/GameUpdates";
import { ErrorUpdate, GameUpdateViewData } from "./game/GameUpdates";
import { createNationsForGame } from "./game/NationCreation";
import { loadTerrainMap as loadGameMap } from "./game/TerrainMapLoader";
import { PseudoRandom } from "./PseudoRandom";
@@ -172,13 +168,7 @@ export class GameRunner {
});
}
// Many tiles are updated to pack it into an array
const tileUpdates = updates[GameUpdateType.Tile];
const packedTileUpdates = new BigUint64Array(tileUpdates.length);
for (let i = 0; i < tileUpdates.length; i++) {
packedTileUpdates[i] = tileUpdates[i].update;
}
updates[GameUpdateType.Tile] = [];
const packedTileUpdates = this.game.drainPackedTileUpdates();
this.callBack({
tick: this.game.ticks(),