Skip to content

feat(geo-layers): pace Tile3DLayer glTF sublayer creation (2/2) - #11151

Open
charlieforward9 wants to merge 1 commit into
fix/scenegraph-first-drawfrom
feat/tile3d-pacing
Open

charlieforward9 wants to merge 1 commit into
fix/scenegraph-first-drawfrom
feat/tile3d-pacing

Conversation

@charlieforward9

@charlieforward9 charlieforward9 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Part 2 of 2, follows #11150. Replaces the pacing in #10784 without a sublayer subclass or scheduler.

Tile3DLayer creates 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 _maxNewTilesPerFrame limits new glTF sublayers per frame
    • Deferred tiles have not drawn, so loaders.gl keeps their parent visible
    • Siblings are created together, so their parent is released as early as possible
    • Point cloud and mesh tiles are not limited: they don't report their first draw
  • Unit tests
  • Documentation and What's New

Verified 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


Note

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 _maxNewTilesPerFrame prop to Tile3DLayer to 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 via requestAnimationFrame, 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.

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]>
@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P1 Prop changes bypass pacing ▶

Summary

Adds experimental _maxNewTilesPerFrame pacing to Tile3DLayer.

  • Tile3DLayer can spread new glTF tile creation across frames.

Acknowledged by charlieforward9: pacing point clouds and meshes is deferred because they do not report first draw. Parent overlap measurement and stencil coverage are also deferred, as is planner-controlled creation order.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Selected glTF tiles without sublayers] --> B[Group siblings and apply limit]
  B --> C[Create allowed sublayers]
  B --> D[Defer remaining tiles]
  D --> E[Request next animation frame]
  E --> A
  D --> F[Props change]
  F --> G[Mark cached tiles needsUpdate]
  G --> H[Update branch creates deferred sublayers]
Loading

Reviews (1) · Last reviewed commit: "feat(geo-layers): pace Tile3DLayer glTF ..." · Reviewed by Greptile

if (tile.selected) {
// render selected tiles
if (!layer) {
if (!layer && !deferredTiles.has(tile)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Prop changes bypass pacing

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f8ac5d2. Configure here.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 83.586% — feat/tile3d-pacing into fix/scenegraph-first-draw. No base build found for fix/scenegraph-first-draw.

@athomct athomct left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. modules/geo-layers/src/tile-3d-layer/tile-3d-layer.ts:501-508 — blocking — a prop change bypasses the limit.
    Evidence: updateState sets needsUpdate = true on every layerMap entry when props change. A deferred tile has an entry but no layer. It skips the guarded if (!layer && !deferredTiles.has(tile)) branch and enters else if (layerCache.needsUpdate), which calls _getSubLayer(tile, undefined) and creates it. A minimal test proves it: limit 1, four new sibling tiles, one renderLayers(), then set needsUpdate on every entry as updateState does. The next renderLayers() calls _getSubLayer 4 times (1 update and 3 new tiles), not 2. On master, updateState also sets needsUpdate for updateTriggersChanged and for a normalizedColors change, 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 example if (deferredTiles.has(tile)) { /* wait */ } else if (!layer) {...} else if (layerCache.needsUpdate) {...}, or use else if (layer && layerCache.needsUpdate). Add a test that changes props between two batches.

  2. modules/geo-layers/src/tile-3d-layer/tile-3d-layer.ts:477-483 — should-fix — the frame callback has no test.
    Evidence: the test stubs requestAnimationFrame and never runs the callback. It clears nextTilesFrame by hand. A mutation that removes layer.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 calls setNeedsUpdate and clears nextTilesFrame. Also check that finalizeState cancels a pending request.

  3. 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, but slice(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".

  4. modules/geo-layers/src/tile-3d-layer/tile-3d-layer.ts — should-fix — the PR conflicts with master.
    Evidence: git merge-tree against master 69b44bd reports content conflicts in tile-3d-layer.ts (the normalized-colors change in updateState and the state type) and in docs/whats-new.md. The base PR #11150 also conflicts with master.
    Suggested change: rebase after #11150, then re-check finding 1 against the new updateState.

  5. modules/geo-layers/src/tile-3d-layer/tile-3d-layer.ts:493 — nit — skip the work without a limit.
    _getDeferredTiles() filters selectedTiles on every renderLayers(), also when the prop has its default value. An early return when _maxNewTilesPerFrame is the default keeps the default path exactly as it was.

  6. nit — shared helper. #11175 adds a near copy of _getDeferredTiles and the frame request to TileLayer and Tile2DLayer. 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). Removing setNeedsUpdate() from the frame callback survives.
  • Probe for finding 1: fails as described (_getSubLayer called 4 times, expected 2).
  • Not run: tsc and lint.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants