mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-04 08:36:10 +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:
+2
-12
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user