Keep the frame rate up while painting a big tilemap (#347)
Painting on the 60x60 map of a project with fifty objects dropped the editor to 20 to 39 fps. A profile of a brush stroke showed four causes, none of them the brush itself. - Each frame of a stroke previews the model. The asset and hierarchy panels then built every row anew, so every label became a new text and a new upload to the GPU. One run spent 46 % of the main thread in those uploads. ListView.setItems now keeps a row whose item draws the same (sameListItem) and builds only the rows that changed. - The brush drew the whole scene on every pointer event, on top of the preview. Now the preview draws what the stroke changed, once a frame. The rectangle tool asks for one drawing a frame for its box. - An animated tile made the view draw in the tick and the preview drew it again in the same frame. animate now asks just before the frame is drawn and stays out when the view was drawn since the tick began. - layoutSymbols ran on every drawing and costs up to the cube of the symbols. SymbolLayoutMemo keeps the spots while no anchor moves. - A painted cell made the map read every "x,y" key again, and once more for each of the eight neighbours of every cell. layerCells reads a layer once per content into an index by place. layerTiles and the blocking cells take their neighbours from there (neighboursIn). parseCellKey reads a key without split, with the same results. The test hook sceneRedraws counts how often the scene view was drawn. Not done: a painted cell still works out the tiles and blocking cells of the whole map again, so that part grows with the map. Tests: - Brush stroke on a copy of the project (stein2, Chrome): 20 to 39 fps before, 47.5 after, 55 to 57 without painting. Labels drawn again during the stroke 2012 before, none after. Scene drawings per frame 1.32 before, 1 after. - One painted cell, headless: 28 to 16 ms on 60x60, 109 to 49 ms on the same map doubled to 120x120. - frame-preview: 2 new, red with the old pointer redraw. - tilemap: 3 new (key reading, index, refresh), list-ping 1 new, symbol-layout 1 new. 5 single reversals turned each red. - e2e 39,40 (melektaus-atx): ALL PASSED, 107 checks (1 new, a fast stroke: 6 drawings in 6 frames, no label drawn again). With the row reuse and the pointer redraw reverted it fails: 24 drawings in 3 frames, and the panels draw their labels again. - Gate (melektaus-atx): CHECK EXIT 0, 260 files, 4038 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
101b12504e
commit
4c7861b5b8
13 files changed
+397
-44
No files matched your search
@@ -354,6 +354,45 @@ export async function tilemap(t) {
|
||||
JSON.stringify({ drawnBefore, drawnHeld, drawnReleased, left: await painted() }),
|
||||
);
|
||||
|
||||
// 40c-iii. However fast the pointer crosses cells, a stroke draws the scene at most once a frame,
|
||||
// and the panels keep their rows instead of drawing every label again (#347).
|
||||
const along = [];
|
||||
for (let x = 0; x < COLUMNS; x++)
|
||||
along.push(await json(`__gm.tilemap.cellAt(${JSON.stringify(MAP_OBJECT)}, ${x}, 2)`));
|
||||
await evaluate(
|
||||
'window.__texts = []; window.__fillText = CanvasRenderingContext2D.prototype.fillText;' +
|
||||
' CanvasRenderingContext2D.prototype.fillText = function (text, ...rest) {' +
|
||||
' window.__texts.push(String(text)); return window.__fillText.call(this, text, ...rest); }',
|
||||
);
|
||||
await t.mouse('mouseMoved', along[0].x, along[0].y);
|
||||
await t.mouse('mousePressed', along[0].x, along[0].y);
|
||||
await settle();
|
||||
const counts = () => json('({ redraws: __gm.sceneRedraws(), drawn: __gm.renderStats().drawn })');
|
||||
const countsBefore = await counts();
|
||||
await evaluate('window.__texts = []');
|
||||
for (let pass = 0; pass < 4; pass++)
|
||||
for (let i = 0; i < COLUMNS; i++) {
|
||||
const p = along[pass % 2 ? COLUMNS - 1 - i : i];
|
||||
await t.mouse('mouseMoved', p.x, p.y, 'left', { buttons: 1 });
|
||||
}
|
||||
await settle();
|
||||
const countsAfter = await counts();
|
||||
// The fps readout is the one text that changes on its own.
|
||||
const redrawnTexts = (await json('window.__texts')).filter((text) => !/fps$/.test(text));
|
||||
await evaluate('CanvasRenderingContext2D.prototype.fillText = window.__fillText');
|
||||
await t.mouse('mouseReleased', along[0].x, along[0].y);
|
||||
await settle();
|
||||
const strokeCells = Object.keys(await painted()).length;
|
||||
await undo();
|
||||
await settle();
|
||||
const redraws = countsAfter.redraws - countsBefore.redraws;
|
||||
const frames = countsAfter.drawn - countsBefore.drawn;
|
||||
check(
|
||||
'a fast stroke draws the scene at most once a frame and no list label again',
|
||||
strokeCells === COLUMNS && redraws <= frames && redrawnTexts.length === 0,
|
||||
JSON.stringify({ strokeCells, redraws, frames, redrawnTexts: redrawnTexts.slice(0, 12) }),
|
||||
);
|
||||
|
||||
// 40d. The rectangle tool fills the box a drag spans.
|
||||
await clickInPanel(t, '__gm.tilemap.toolAt("rect")');
|
||||
await settle();
|
||||
|
||||
Reference in new issue
Block a user