A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
perf(ui): avoid geometry writes for idle scrollbar thumbs
yhhe7598d4599cf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a54b69e5a..309c5b3b3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,6 +22,8 @@ published separately; it ships inside the editor.### Fixed+- **Idle scrollbars stop forcing UI layout work.** Overlay thumbs write their node geometry only when position, length or units change, including during fade-out and after becoming invisible. Comparisons use the native float precision so fractional thumb sizes settle instead of dirtying layout every frame; scrolling and viewport/content resizing still refresh their geometry.+- **Running tilemaps follow published tileset updates.** Tileset publication versions invalidate each app's cached render table, animations and collision model after a successful replacement, without requiring a reference edit or scene reload. Failed replacements keep the working version; unchanged frames read only a version counter and avoid rebuilding the table or resolving resource paths again.- **Lazy tilemaps acquire and release tileset slots correctly.** Runtime-only tileset references use owned slot acquisitions rather than the retired generic loader interface. Failed loads retry after the asset cooldown, shared references deduplicate requests, and removing the last layer or resetting the runtime releases both completed and late acquisitions.diff --git a/sdk/src/ui/behavior/scrollbar.ts b/sdk/src/ui/behavior/scrollbar.tsindex 922c06118..ef50c4435 100644--- a/sdk/src/ui/behavior/scrollbar.ts+++ b/sdk/src/ui/behavior/scrollbar.ts@@ -14,7 +14,7 @@ import { defineSystem, type SystemDef } from '../../ecs/system';import { Res, Time, type TimeData } from '../../ecs/resource';import type { World } from '../../ecs/world';import type { Entity, Vec2 } from '../../types';-import { px } from '../core/dimension';+import { px, DimensionUnit } from '../core/dimension';import { spawnUIEntity } from '../core/compose';import { UINode, UIPositionType, type UINodeData } from '../core/ui-node';import { UIVisual, type UIVisualData } from '../core/ui-visual';@@ -75,14 +75,21 @@ function layoutThumb(const along = maxOffset > 0 ? (offset / maxOffset) * range : 0;const n = world.get(thumb, UINode) as UINodeData;- if (axis === 'v') {- n.insetTop = px(along);- n.height = px(len);- } else {- n.insetLeft = px(along);- n.width = px(len);+ // Match the f32 fields read back from the native node before deciding to write.+ const position = Math.fround(along), length = Math.fround(len);+ const currentPosition = axis === 'v' ? n.insetTop : n.insetLeft;+ const currentLength = axis === 'v' ? n.height : n.width;+ if (currentPosition.unit !== DimensionUnit.Px || currentPosition.value !== position+ || currentLength.unit !== DimensionUnit.Px || currentLength.value !== length) {+ if (axis === 'v') {+ n.insetTop = px(position);+ n.height = px(length);+ } else {+ n.insetLeft = px(position);+ n.width = px(length);+ }+ world.insert(thumb, UINode, n);}- world.insert(thumb, UINode, n);const vis = world.get(thumb, UIVisual) as UIVisualData;const a = THUMB_ALPHA * alpha;diff --git a/sdk/tests/ui-scroll-motion-wasm.test.ts b/sdk/tests/ui-scroll-motion-wasm.test.tsindex e794ec10b..78245400f 100644--- a/sdk/tests/ui-scroll-motion-wasm.test.ts+++ b/sdk/tests/ui-scroll-motion-wasm.test.ts@@ -1,6 +1,6 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team-import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';+import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';import { App, flushPendingRegistrations } from '../src/app/app';import { AppContext, setDefaultContext } from '../src/ecs/context';import { Input, InputState, inputEventCallbacks } from '../src/input/input';@@ -43,6 +43,23 @@ describe.skipIf(!HAS_WASM)('scroll motion ownership on real WASM', () => {async function drag() {input.noteMouseDown(0); await step(0); await step(40); await step(80);}+ it('does not dirty native thumb geometry after fractional lengths settle', async () => {+ const scroll = new ScrollContainer({ viewportSize: { x: 100, y: 100 },+ contentSize: { x: 300, y: 300 }, direction: 'both' });+ plugin.attachScrollContainer(entity, scroll); await step(0);+ scroll.scrollBy({ x: 50, y: 50 }); await step(0);+ const { UINode } = await import('../src/ui/core/ui-node');+ const { UIVisual } = await import('../src/ui/core/ui-visual');+ const thumbs = app.world.getEntitiesWithComponents([UINode, UIVisual]);+ expect(thumbs).toHaveLength(2);+ const insert = vi.spyOn(app.world, 'insert');+ try {+ for (let i = 0; i < 120; i++) await step(0);+ expect(insert.mock.calls.filter(([, component]) => component === UINode)).toHaveLength(0);+ for (const thumb of thumbs) expect(app.world.get(thumb, UIVisual).color.a).toBe(0);+ } finally { insert.mockRestore(); }+ });+it('a replaced container does not inherit an active pointer drag', async () => {const old = container(); plugin.attachScrollContainer(entity, old); await drag();expect(old.getOffset().y).toBe(80);diff --git a/sdk/tests/ui-scrollbar.test.ts b/sdk/tests/ui-scrollbar.test.tsindex 3de719b1b..9254a3e74 100644--- a/sdk/tests/ui-scrollbar.test.ts+++ b/sdk/tests/ui-scrollbar.test.ts@@ -4,7 +4,7 @@* @file UIScrollbarSystem — overlay thumbs appear on scroll, track the offset,* and fade out after idle.*/-import { describe, it, expect, beforeEach } from 'vitest';+import { describe, it, expect, beforeEach, vi } from 'vitest';import { createScrollbarSystem } from '../src/ui/behavior/scrollbar';import { ScrollContainer, ScrollContainerRegistry } from '../src/ui/collection/scroll-container';import { UINode } from '../src/ui/core/ui-node';@@ -121,6 +121,19 @@ describe('UIScrollbarSystem', () => {expect(thumbs()).toHaveLength(0);});+ it('does not rewrite unchanged geometry during fade or after it becomes hidden', () => {+ tick(); scroll.scrollBy({ x: 0, y: 50 }); tick();+ const writes = vi.spyOn(world, 'insert');+ for (let i = 0; i < 120; i++) tick();+ expect(writes.mock.calls.filter(([, component]) => component === UINode)).toHaveLength(0);+ expect((world.get(thumbs()[0], UIVisual) as { color: { a: number } }).color.a).toBe(0);+ writes.mockClear();+ for (let i = 0; i < 60; i++) tick();+ expect(writes).not.toHaveBeenCalled();+ scroll.setContentSize({ x: 100, y: 600 }); tick();+ expect(writes.mock.calls.filter(([, component]) => component === UINode)).toHaveLength(1);+ });+it('a horizontal-only container never grows a vertical thumb', () => {registry.detach(viewport as number);const h = new ScrollContainer({diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 9d9cd36cc..226480f19 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'perf(ui): avoid geometry writes for idle scrollbar thumbs':+ { note: 'Idle scrollbars stop forcing UI layout work.' },'fix(tilemap): refresh layers after tileset publication changes':{ note: 'Running tilemaps follow published tileset updates.' },'fix(tilemap): own lazy tileset loads and retry failures':