Repository navigation
feat(geo-layers): pace Tile3DLayer glTF sublayer creation (2/2) - #11151
charlieforward9 wants to merge 1 commit into
Conversation
Creating a sublayer uploads a tile to the GPU, so many tiles arriving in one frame can stall it. The experimental _maxNewTilesPerFrame prop limits how many new glTF tiles get a sublayer per frame. Tiles over the limit are created on later frames, siblings together; until then they have not drawn, so loaders.gl keeps their parent visible. Point cloud and mesh tiles do not report their first draw, so they are not limited. Co-Authored-By: Claude Opus 5.5 <[email protected]>
[Medium impact] The change affects tile creation timing within Tile3DLayer. Fix the prop-change bypass before merging so the configured tile limit remains effective. Findings
SummaryAdds experimental
Acknowledged by
|
| if (tile.selected) { | ||
| // render selected tiles | ||
| if (!layer) { | ||
| if (!layer && !deferredTiles.has(tile)) { |
There was a problem hiding this comment.
Changing opacity or another prop while tiles are deferred bypasses _maxNewTilesPerFrame. updateState marks every cached tile as needsUpdate, including tiles without a sublayer. Those tiles skip the guarded creation branch but then enter else if (layerCache.needsUpdate), creating all remaining sublayers at once. This brings back the GPU upload burst and interaction stalls the limit is meant to prevent.
Apply the deferral check to both branches, and add a test that changes props between batches.
Knowledge Base Used: Layer lifecycle and state
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f8ac5d2. Configure here.
| if (tile.selected) { | ||
| // render selected tiles | ||
| if (!layer) { | ||
| if (!layer && !deferredTiles.has(tile)) { |
There was a problem hiding this comment.
Prop updates bypass tile pacing
Medium Severity
_maxNewTilesPerFrame does not apply after a props change. Selected glTF tiles still waiting for a sublayer sit in layerMap without a layer, so a later needsUpdate falls through and creates them immediately. That can upload every deferred tile in one frame, which is the stall this pacing is meant to avoid. New sublayers already pick up current props when they are created, so this path is not required for correctness.
Reviewed by Cursor Bugbot for commit f8ac5d2. Configure here.
athomct
left a comment
There was a problem hiding this comment.
Head f8ac5d2. Base fix/scenegraph-first-draw (#11150). Verdict: request changes (finding 1 defeats the feature after any prop change).
Summary
This PR adds the experimental prop _maxNewTilesPerFrame to Tile3DLayer. When more new glTF tiles are selected than the limit, the layer creates sublayers for the first tiles only, groups siblings first, and asks for another update on the next animation frame. Deferred tiles have not drawn, so loaders.gl keeps their parent visible. Point cloud and mesh tiles are not limited. The idea is sound and small, and it depends correctly on #11150 for the first-draw signal. The default path does not change. The PR tests pass. But a prop change while tiles wait creates every waiting tile in one frame, and the frame callback has no test.
Findings
-
modules/geo-layers/src/tile-3d-layer/tile-3d-layer.ts:501-508 — blocking — a prop change bypasses the limit.
Evidence:updateStatesetsneedsUpdate = trueon everylayerMapentry when props change. A deferred tile has an entry but nolayer. It skips the guardedif (!layer && !deferredTiles.has(tile))branch and enterselse if (layerCache.needsUpdate), which calls_getSubLayer(tile, undefined)and creates it. A minimal test proves it: limit 1, four new sibling tiles, onerenderLayers(), then setneedsUpdateon every entry asupdateStatedoes. The nextrenderLayers()calls_getSubLayer4 times (1 update and 3 new tiles), not 2. Onmaster,updateStatealso setsneedsUpdateforupdateTriggersChangedand for anormalizedColorschange, so this path runs more often after a rebase. The Greptile and Cursor bots flagged the same path.
Suggested change: check the deferral first, for exampleif (deferredTiles.has(tile)) { /* wait */ } else if (!layer) {...} else if (layerCache.needsUpdate) {...}, or useelse if (layer && layerCache.needsUpdate). Add a test that changes props between two batches. -
modules/geo-layers/src/tile-3d-layer/tile-3d-layer.ts:477-483 — should-fix — the frame callback has no test.
Evidence: the test stubsrequestAnimationFrameand never runs the callback. It clearsnextTilesFrameby hand. A mutation that removeslayer.setNeedsUpdate()from the callback passes all tests. With that bug, deferred tiles wait until some other update, for example a camera move.
Suggested change: capture the callback in the test, run it, and check that it callssetNeedsUpdateand clearsnextTilesFrame. Also check thatfinalizeStatecancels a pending request. -
modules/geo-layers/src/tile-3d-layer/tile-3d-layer.ts:468-485 — question — siblings can split across frames.
Evidence: the sort puts siblings next to each other, butslice(maxNewTiles)can cut inside a sibling group. With a limit of 2 and four siblings, two wait. loaders.gl then keeps the parent until the last sibling draws. The docs say "siblings together".
Suggested change: either round the batch up to the end of the current sibling group, or change the docs to "siblings first". -
modules/geo-layers/src/tile-3d-layer/tile-3d-layer.ts — should-fix — the PR conflicts with
master.
Evidence:git merge-treeagainstmaster69b44bd reports content conflicts intile-3d-layer.ts(the normalized-colors change inupdateStateand the state type) and indocs/whats-new.md. The base PR #11150 also conflicts withmaster.
Suggested change: rebase after #11150, then re-check finding 1 against the newupdateState. -
modules/geo-layers/src/tile-3d-layer/tile-3d-layer.ts:493 — nit — skip the work without a limit.
_getDeferredTiles()filtersselectedTileson everyrenderLayers(), also when the prop has its default value. An earlyreturnwhen_maxNewTilesPerFrameis the default keeps the default path exactly as it was. -
nit — shared helper. #11175 adds a near copy of
_getDeferredTilesand the frame request toTileLayerandTile2DLayer. A small shared helper for "request one more update next frame" can keep the three copies in step.
Tests run (local, macOS, headless Chromium)
- Node:
test/modules/mesh-layers,test/modules/geo-layers/tile-3d-layer: 8/8 pass. - Headless:
test/modules/mesh-layers,test/modules/geo-layers/tile-3d-layer: 14/14 pass. - Render:
scenegraph-layer.spec.ts,simple-mesh-layer.spec.ts: 20/20 pass. - Mutation check of the PR's tests: removing the deferral check, removing the sibling sort, and
<=to<at the limit each fail a test (good). RemovingsetNeedsUpdate()from the frame callback survives. - Probe for finding 1: fails as described (
_getSubLayercalled 4 times, expected 2). - Not run:
tscand lint.


Part 2 of 2, follows #11150. Replaces the pacing in #10784 without a sublayer subclass or scheduler.
Tile3DLayercreates a sublayer, which uploads its tile to the GPU, for every new tile in the frame it is selected, so bursts of arriving tiles stall interaction.Change List
Tile3DLayer: experimental_maxNewTilesPerFramelimits new glTF sublayers per frameVerified with the geo-layers and mesh-layers node tests (the new test fails on master) and the tile-3d-layer and mesh-layers headless tests.
TODO
PointCloudLayerandMeshLayer, so their tiles keep a fallback and can be pacedNote
Low Risk
Low risk as it introduces an opt-in experimental property defaulting to unbounded tile creation, leaving existing behavior unchanged.
Overview
Adds an experimental
_maxNewTilesPerFrameprop toTile3DLayerto pace the creation and GPU upload of glTF sublayers across animation frames. When new selected glTF tiles exceed this limit, excess tiles are deferred to subsequent frames viarequestAnimationFrame, prioritizing siblings together so parent tiles can be released as quickly as possible.Point cloud and mesh tiles remain unaffected by the limit, and existing behavior is preserved by default with an unbounded limit.
Reviewed by Cursor Bugbot for commit f8ac5d2. Bugbot is set up for automated code reviews on this repo. Configure here.