VectorTileLayer瓦片GC回收使用ArrayBuffer复用池,提升地图在频繁缩放和拖拽时候的流畅度#2843
Open
HGX-DJK wants to merge 5 commits intomaptalks:masterfrom
Open
VectorTileLayer瓦片GC回收使用ArrayBuffer复用池,提升地图在频繁缩放和拖拽时候的流畅度#2843HGX-DJK wants to merge 5 commits intomaptalks:masterfrom
HGX-DJK wants to merge 5 commits intomaptalks:masterfrom
Conversation
fuzhenn
requested changes
Mar 14, 2026
Member
|
👍 复用arraybuffer确实是好思路。
测试命令: |
…加一个静态的 clear()方法,并在移除图层或地图时,由Dispatcher触发清理
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.
优化前:每加载一个瓦片,Worker 线程都会申请一大块新的内存(ArrayBuffer)来存储几何数据。渲染完成后,这块内存被释放。在大量瓦片更替时,浏览器会频繁触发垃圾回收(Garbage Collection),导致主线程出现微小的“掉帧”或卡顿。
优化后:建立一个内存池。瓦片不再使用时,内存不被销毁,而是通过 returnBuffers 机制送回 Worker。下次加载新瓦片时,直接从池中取用旧内存。这极大地减少了 GC 的频率,让动画更加顺滑。
Worker → 主线程:几何数据打包好后传给主线程渲染
主线程 → Worker:当瓦片被销毁(deleteTile)时,我们主动收集这些 ArrayBuffer,并发送指令将内存返还给 Worker 的内存池,而非丢弃