mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-02 03:18:12 +00:00
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:
@@ -12,12 +12,18 @@ import {
|
||||
TrainType,
|
||||
UnitType,
|
||||
} from "./Game";
|
||||
import { TileRef, TileUpdate } from "./GameMap";
|
||||
import { TileRef } from "./GameMap";
|
||||
|
||||
export interface GameUpdateViewData {
|
||||
tick: number;
|
||||
updates: GameUpdates;
|
||||
packedTileUpdates: BigUint64Array;
|
||||
/**
|
||||
* Packed tile updates as `[tileRef, state]` uint32 pairs.
|
||||
*
|
||||
* `tileRef` is a `TileRef` (fits in uint32), and `state` is the packed per-tile
|
||||
* state (`uint16`) stored in a `uint32` lane.
|
||||
*/
|
||||
packedTileUpdates: Uint32Array;
|
||||
playerNameViewData: Record<string, NameViewData>;
|
||||
tickExecutionDuration?: number;
|
||||
pendingTurns?: number;
|
||||
@@ -29,6 +35,7 @@ export interface ErrorUpdate {
|
||||
}
|
||||
|
||||
export enum GameUpdateType {
|
||||
// Tile updates are delivered via `packedTileUpdates` on the outer GameUpdateViewData.
|
||||
Tile,
|
||||
Unit,
|
||||
Player,
|
||||
@@ -54,7 +61,6 @@ export enum GameUpdateType {
|
||||
}
|
||||
|
||||
export type GameUpdate =
|
||||
| TileUpdateWrapper
|
||||
| UnitUpdate
|
||||
| PlayerUpdate
|
||||
| AllianceRequestUpdate
|
||||
@@ -112,11 +118,6 @@ export interface ConquestUpdate {
|
||||
gold: Gold;
|
||||
}
|
||||
|
||||
export interface TileUpdateWrapper {
|
||||
type: GameUpdateType.Tile;
|
||||
update: TileUpdate;
|
||||
}
|
||||
|
||||
export interface UnitUpdate {
|
||||
type: GameUpdateType.Unit;
|
||||
unitType: UnitType;
|
||||
|
||||
Reference in New Issue
Block a user