Skip to content

feat(geo-layers): pace sublayer creation of hidden 2D tiles (2/2) - #11175

Open
charlieforward9 wants to merge 2 commits into
codex/tile-priority-on-master-demofrom
feat/tile2d-pacing
Open

charlieforward9 wants to merge 2 commits into
codex/tile-priority-on-master-demofrom
feat/tile2d-pacing

Conversation

@charlieforward9

@charlieforward9 charlieforward9 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Part 2 of 2, follows #10306. 2D counterpart of #11151.

TileLayer creates sublayers for every loaded tile in its cache, including hidden ones such as prefetched coverage, and only hides them at draw time. A burst of loaded tiles generates attributes and GPU buffers in one frame. A loaded 2D tile is shown as soon as it is visible, so only hidden tiles can wait.

Change List

  • TileLayer: experimental _maxNewTilesPerFrame limits new sublayers per frame
    • Visible tiles are always created and count toward the limit
    • Hidden tiles wait for later frames, in request order
  • Tileset2D: expose getRequestPriority
  • Tile2DLayer: same prop; tiles visible in any view are created
  • Unit tests
  • Documentation and What's New

Verified with the geo-layers node tests (the new tests fail without the change) and the tileset-2d, tile-layer and Tile2DLayer headless tests.


Note

Low Risk
The change introduces an opt-in experimental prop defaulting to no limit, leaving default rendering behavior unchanged.

Overview
Adds an experimental _maxNewTilesPerFrame prop to TileLayer and Tile2DLayer to spread sublayer creation for hidden tiles across frames, reducing frame drops caused by bulk attribute generation and GPU uploads. Visible tiles are always created immediately to prevent rendering holes, while excess hidden tiles—such as prefetched LOD coverage—are queued and instantiated over subsequent animation frames.

To support prioritization of deferred tiles, Tileset2D exposes getRequestPriority to order hidden tile creation by importance. Deferrals schedule follow-up frames via requestAnimationFrame and clean up pending requests on layer finalization.

Reviewed by Cursor Bugbot for commit 0e38887. Bugbot is set up for automated code reviews on this repo. Configure here.

charlieforward9 and others added 2 commits November 17, 2026 19:20
TileLayer creates sublayers for every loaded tile in the cache, including
hidden ones such as prefetched coverage, and only filters them at draw
time. The experimental `_maxNewTilesPerFrame` prop limits new sublayers
per frame. Visible tiles are always created and count toward the limit;
hidden tiles wait for later frames, in request order. `Tileset2D` exposes
`getRequestPriority` for that order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add `_maxNewTilesPerFrame` to Tile2DLayer, as in TileLayer. Tiles visible
in any of the layer's views are always created.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Low impact] The change reaches tile sublayer creation in two tile layers.

The PR appears safe to merge, with a non-blocking test gap around follow-up frames.

Findings

  1. P2 Frame callbacks go untested ▶

Summary

Adds opt-in pacing for hidden tile sublayers while keeping visible tiles immediate.

  • Tile layers spread hidden tile setup across later frames.

Reviews (1) · Last reviewed commit: "feat(proposals): pace sublayer creation ..." · Reviewed by Greptile

Comment on lines +69 to +71
// The frame request clears its id before updating the layer
layer.state.nextTilesFrame = undefined;
expect(getCreatedIds(), 'creates the rest next frame').toEqual([

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Frame callbacks go untested. The requestAnimationFrame mock discards its callback, and both tests clear nextTilesFrame and call renderLayers() themselves. They would still pass if the callback stopped calling setNeedsUpdate(), leaving deferred tiles unfinished in an idle map. Capture and run the callback, then check that it requests an update and that the next update creates the remaining tiles without manually clearing state.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 82.594% — feat/tile2d-pacing into codex/tile-priority-on-master-demo. No base build found for codex/tile-priority-on-master-demo.

@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 0e38887. Base codex/tile-priority-on-master-demo (#10306). Verdict: comment (approve after finding 1; the rest are small).

Summary

This PR adds the experimental prop _maxNewTilesPerFrame to TileLayer and the proposed Tile2DLayer. Visible tiles always get their sublayers in the same frame, and they count toward the limit. Loaded tiles that no view shows, such as prefetched coverage, wait for later frames in request-priority order. Tiles that no view needs go last. Tileset2D gets a public getRequestPriority. The design avoids the hole problem of #11151, because a hidden tile has nothing to show. Unlike #11151, the prop-change path cannot bypass the limit here, because the deferral check comes first in renderLayers. The PR tests pass, and the main branches of the logic are guarded by them. The frame callback is not tested, and a new public method has no docs.

Findings

  1. modules/geo-layers/src/tile-layer/tile-layer.ts:446-452 and modules/proposals/src/layers/tile-2d-layer/tile-2d-layer.ts:652-656 — should-fix — the frame callback has no test.
    Evidence: the test stub of requestAnimationFrame drops the callback, and both tests clear nextTilesFrame by hand. Removing layer.setNeedsUpdate() from either callback passes all tests. With that bug, hidden tiles stay without sublayers on an idle map. Removing cancelAnimationFrame from TileLayer.finalizeState also passes. The Greptile bot flagged the same gap.
    Suggested change: capture and run the callback. Check that it requests an update, clears nextTilesFrame, and that the next renderLayers() creates the rest. Check that finalizeState cancels a pending request.

  2. modules/geo-layers/src/tileset-2d/tileset-2d.ts:654 — should-fix — getRequestPriority is new public API without docs.
    Evidence: the method is public, but docs/api-reference/proposals/tileset-2d.md does not list it. Its values are internal bands (selected, visible, coverage, -1 for not needed), and other PRs change these bands. For example, #11286 adds a preload band before them.
    Suggested change: mark it experimental (an @experimental TSDoc tag, or a _-prefixed public name other than the existing private _getRequestPriority). Document only the contract that callers can use: "lower loads first, negative means not needed".

  3. modules/geo-layers/src/tile-layer/tile-layer.ts:429-432 — question — hidden tiles can wait indefinitely while the camera moves.
    Evidence: maxHiddenTiles is limit - newVisibleTiles, and is 0 when the visible tiles use up the limit. During a long pan or flight with new visible tiles on most frames, no hidden tile gets a sublayer. When those tiles then become visible, they are all created in one frame, which is the burst this prop wants to avoid. A probe with limit 1 showed four new visible tiles in the first frame and no hidden tile created in that frame.
    Suggested change: either reserve a small budget for hidden tiles (for example at least one per frame), or say in the docs that hidden tiles only advance on frames with spare budget.

  4. modules/geo-layers/src/tile-layer/tile-layer.ts:438-443 — nit — the "not needed go last" rule has no test.
    Evidence: removing the mapping of negative priorities to Number.MAX_SAFE_INTEGER passes all tests.
    Suggested change: add one tile with priority -1 to the first test and check that it is created last.

  5. modules/geo-layers/src/tile-layer/tile-layer.ts:470 and tile-2d-layer.ts:666 — nit — skip the work without a limit.
    _getDeferredTiles filters every cached tile on every renderLayers(), also with the default limit. An early return for the default keeps the default path exactly as on master.

  6. Stack — should-fix — the PR and its base conflict with master.
    Evidence: git merge-tree against master 69b44bd reports conflicts in tile-layer.ts (a state field from the normalized-colors change), docs/whats-new.md and test/modules/geo-layers/tileset-2d/tileset-2d.spec.ts. The base #10306 alone conflicts in docs/whats-new.md and the same test file. master now uses math.gl 5, so #10306's test import of Matrix4 from @math.gl/core must become @math.gl/core/matrix; the headless test file fails to load otherwise.
    Note on order: this PR uses only Tileset2D._getRequestPriority, which is on master. But on master, every hidden tile has priority -1, so the sort does nothing without #10306. Landing #10306 first, as planned, is the correct order. This PR does not depend on #11150 or #11151.

Tests run (local, macOS, headless Chromium)

  • Node: test/modules/geo-layers: 67/67 pass (includes tile-layer-pacing.node.spec.ts, 4 tests).
  • Headless: tileset-2d, tile-layer, terrain-layer.spec.ts, mvt-layer: 71/71 pass.
  • Mutation check of the PR's tests: ignoring the deferral (both layers), deferring visible tiles (both layers), dropping the priority sort, and not counting visible tiles toward the limit each fail a test (good). Removing setNeedsUpdate() from either frame callback, the negative-priority mapping, and the cancelAnimationFrame call each survive.
  • Not run: tsc and lint.

Interaction with #11286 (TileLayer _preloadTransitionTarget) — separate note, not a finding

I am the author of #11286, so I checked how the two PRs interact. In a scratch worktree, I merged this PR head (0e38887, which includes #10306) onto the #11286 head 7940d8b. I resolved the conflicts so that both features stay, then ran the tests and two probes.

Conflicts. Only one conflict comes from this PR itself: a trivial state-type hunk in tile-layer.ts (nextTilesFrame next to normalizedTileColors). All other conflicts come from the base #10306: 11 hunks in tileset-2d.ts (prefetchTiles next to preloadTiles in the consumer state, _getRequestPriority, _pruneRequests, _resizeCache, updateConsumer), 2 hunks in tile-2d-view.ts (the updateConsumer call), and doc hunks in docs/whats-new.md and docs/api-reference/proposals/tileset-2d.md. They are mechanical, but updateConsumer needs one agreed signature, for example (id, selected, visible, prefetchTiles?, preloadIndices?).

Tests after the merge. Node test/modules/geo-layers plus transition-target.node.spec.ts: 82/82 pass. Headless tileset-2d, tile-layer, terrain-layer, mvt-layer: 72/72 pass (after the @math.gl/core/matrix import fix in the #10306 test).

Behaviour 1: priority bands collide (from #10306, visible only when both land). #11286 shifts selected and visible priorities by PRELOAD_PRIORITY_OFFSET (1e8) while preload tiles exist. #10306 gives coverage PREFETCH_TILE_PRIORITY + rank (2e8 + rank) with no shift. During a transition, a visible placeholder then gets 2e8 + distance, and coverage gets 2e8 + rank, so coverage loads before visible placeholders. A probe test reproduces it: visible 200000015.3 against coverage 200000000. Adding the same offset in _getPrefetchPriority fixes it, and all 79 node tests then pass. Whichever PR lands second must add this offset.

Behaviour 2: pacing and preload work together, in the right order. Preload tiles are loaded but not visible, so this PR treats them as hidden and defers their sublayers. Their priority is their preload rank (0, 1, ...), which is lower than every other band, so they get sublayers before coverage and before tiles that no view needs. A probe with limit 1 confirmed it: the first hidden tile created was a preload tile. This lowers the in-flight cost that #11286 adds, because preload tiles build sublayers only on frames with spare budget.

Behaviour 3: burst at arrival. Preload tiles that are still deferred become visible when the camera arrives, and visible tiles are always created in the same frame. In the probe, one of the two preload tiles got its sublayer at the arrival frame. With a large target viewport and a low limit, most target tiles can arrive in one frame, together with finding 3 above (hidden tiles get no budget while visible tiles use it). This is a trade-off to measure, not a defect: the bench for #11286 should record the arrival frame time with and without _maxNewTilesPerFrame.

Behaviour 4: no conflict in eviction or aborts. This PR does not change the tile cache, requests, or aborts. Preload tiles keep their #11286 protection from aborts and LRU eviction.

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