Halve the frame time of a playing scene with a tilemap (#284)
The performance panel showed Physics and Editor as the large parts of a frame in a scene of 222 entities. Nearly all of it came from a tilemap that only stands there. - Whoever writes cells in place now says so with cellsChanged. Only then does cellsVersion compare the content. The comparison ran about 60 times per frame and was the largest single item at 14 percent. - The four writers call it: the painter during and at the end of a stroke, PaintTilesCommand on execute and on undo. A new writer that forgets it stays invisible. - The game view is drawn once per frame in play. With an animated tile in view it was drawn twice, once by the run and once by animate(). animate() now gets the redraw count from the start of the tick. - TilemapField builds the geometry of a mesh only when its source changes: the cells, the tile size, the origin or the image. For that groupByTile and layerRows return the same objects for the same list. - PhysicsSystem skips a tilemap whose source and switch are unchanged. The switch is kept because a map that starts switched off would otherwise have dead colliders once it is switched on. - World.syncToModel looks entities and assets up in a map per pass instead of a linear search per object. Measured on stein2 with a copy of the reference project, ms per frame: Physics 2.64 to 0.97, Drawing 6.89 to 2.56, Editor 1.95 to 1.31. Left open: syncToModel still mirrors every entity every frame. That is its own issue. Tests: - Gate: 198 files, 2887 tests (2883 + 4), exit 0 - e2e 1-17,28,33,39-43,59: 810 checks passed, 40 has +3 - Smokes: 24 / 19 / 21, exit 0 - Three unit tests wrote cells directly and now call cellsChanged - Eleven counter-probes fail. Two did not at first: the stroke needed a check of its own, the physics test has to start with the map switched off. That last one was repeated on stein2 only. - e2e total 1613 is computed, not measured in a full run Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6491888f56
commit
cfd288c4b7
15 files changed
+303
-43
No files matched your search
@@ -318,18 +318,23 @@ export class World {
|
||||
}
|
||||
const reparented = this.movedUp.size > 0;
|
||||
this.movedUp.clear();
|
||||
const alive = new Set(this.entities.map((e) => e.objectId));
|
||||
// Looked up once for the whole pass: asking the list per object made this grow with the square
|
||||
// of the entities, every frame of a run (#284). The first of an id counts, as `findByObjectId` has it.
|
||||
const alive = new Map<string, Entity>();
|
||||
for (const e of this.entities) if (!alive.has(e.objectId)) alive.set(e.objectId, e);
|
||||
const assets = new Map<string, Asset>();
|
||||
for (const asset of this.project.assets) if (!assets.has(asset.id)) assets.set(asset.id, asset);
|
||||
const before = scene.objects.length;
|
||||
for (let i = scene.objects.length - 1; i >= 0; i--) {
|
||||
const object = scene.objects[i]!;
|
||||
const asset = findAsset(this.project, object.assetId);
|
||||
const asset = assets.get(object.assetId);
|
||||
if (asset && isPlaceableType(asset.type) && !alive.has(object.id)) scene.objects.splice(i, 1);
|
||||
}
|
||||
for (const object of resolveObjects(this.project, scene)) {
|
||||
// A dragged object's place belongs to the drag, which reaches the entity on the next re-read.
|
||||
if (this.held.has(object.id)) continue;
|
||||
const entity = this.findByObjectId(object.id);
|
||||
const asset = entity && findAsset(this.project, entity.assetId);
|
||||
const entity = alive.get(object.id);
|
||||
const asset = entity && assets.get(entity.assetId);
|
||||
if (!entity || !asset) continue;
|
||||
const p = object.position;
|
||||
const moved = p.x !== entity.x || p.y !== entity.y || p.z !== entity.z;
|
||||
|
||||
Reference in new issue
Block a user