refactor: optimize tile rendering: prevent unnecessary reloads and smooth opacity updates#138
Merged
airslice merged 5 commits intoJun 2, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
Optimizes Cesium imagery tile rendering by avoiding unnecessary layer recreation. Layers are now kept in a Map keyed by tile id across renders; if only opacity changes, layer.alpha is mutated in place instead of removing/re-adding the layer. Layer removal on effect cleanup is deferred to the next render, with a dedicated unmount cleanup effect to prevent leaks. Regression tests cover the reuse and recreation paths.
Changes:
- Persist
CesiumImageryLayerinstances inlayersRefand reuse them when tile properties (other than opacity) are unchanged, updatingalphadirectly on opacity-only changes. - Replace per-effect-cleanup layer removal with id-diffed removal at the start of the next run, plus a separate unmount-only cleanup effect.
- Extend
Imagery.test.tsto assert no add/remove on opacity-only updates and that provider-type changes still trigger recreation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/engines/Cesium/core/Imagery.tsx | Introduces layer reuse map, opacity-only fast path, and split unmount cleanup effect. |
| src/engines/Cesium/core/Imagery.test.ts | Updates and adds regression tests for opacity reuse and type-change recreation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
While alpha branch already prevents unnecessary provider recreation with
stableTiles, layers are still completely destroyed and recreated on every tile update—even when only opacity changes. This causes:Solutions
1. Layer Reuse with Opacity Optimization
Mapkeyed by tile IDlayer.alphadirectly (no recreation)2. Provider Reference Comparison
prevProvider === currentProviderbefore reusingcesiumIonAccessTokenorcustomProviderURL updates)3. Smart Layer Lifecycle
Implementation
Changes to
src/engines/Cesium/core/Imagery.tsx:layersRefMap storing layers with tile and provider (lines 78-88)layer.alphadirectly for opacity-only changes (lines 158-161)Tests added to
src/engines/Cesium/core/Imagery.test.ts:Results
✅ Opacity changes: Instant property update, zero flicker
✅ Provider changes: Correctly detected and layers recreated
✅ Layer reuse: 0 recreations when only opacity changes, proper recreation when needed