Skip to content

Conversation

@deyihu
Copy link
Collaborator

@deyihu deyihu commented Oct 31, 2025

Q%XE%}3V@4I({PC9SNP0YTR

@deyihu deyihu requested a review from fuzhenn November 6, 2025 06:25
continue;
}
if (!Array.isArray(feats)) {
feats = [feats];
Copy link
Member

Choose a reason for hiding this comment

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

这里会创建新的array对象,建议在循环外创建一个临时array,每次用 array[0] = feats; 赋值,以减少创建的临时数组对象数量

super(...args);
this.features = {};
//使用array结构,更好的遍历的性能,遍历时注意null和空洞的情况
this.features = [];
Copy link
Member

@fuzhenn fuzhenn Nov 10, 2025

Choose a reason for hiding this comment

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

有个潜在的问题,geometry的uid生成是全局性,而且全局不会重复。
如果存在多个点线面图层:

  • 第一个图层的uid会从0开始,uid 等于所有图层中 geometries 数量
  • 后续图层的uid都不从0开始
  • 因为uid不从0开始,后续图层的features数组开头会存在undefined对象
  • 如果某个图层新增了Geometry,因为uid是全局的,新Geometry的uid可能比当前features中最大的uid要大很多,新增Geometry和前一个Geometry之间会产生大量的undefined对象

我感觉可以这么改进:

  • this.features改回{}
  • checkVisible 逻辑改为遍历 Object.values(this.features)
  • 如果 Object.values 存在性能瓶颈,可以把values缓存为属性,新增一个 this.featureValues = Object.values(this.features)
  • 每次this.features发生变化时,也更新 this.featureValues

@fuzhenn fuzhenn merged commit 7555752 into maptalks:master Nov 10, 2025
3 checks passed
@deyihu deyihu deleted the checkfeaturesvisible-perf branch November 10, 2025 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants