Skip to content

Conversation

kerm1it
Copy link
Member

@kerm1it kerm1it commented Jun 3, 2020

@kerm1it
Copy link
Member Author

kerm1it commented Jun 4, 2020

@afc163 @zombieJ 麻烦review一下看这样写有没有问题?

@kerm1it
Copy link
Member Author

kerm1it commented Jun 4, 2020

@zombieJ 改好了,现在新加了一个hook在组件内部存储 optionMap, 然后 findValueOption 查询时用返回的 optionMap 查询,又因为 isValueDisabledgetLabeledValue 等方法都依赖于 findValueOption 所以对应的方法参数和类型都要改。

还有一种就是新加的hook直接返回一个 findValueOption 方法,组件内部的调用都使用这个,isValueDisabledgetLabeledValue 这些方法调用时直接把 findValueOption 的查询结果传进去,就不依赖于 findValueOption,这样外面就不需要传入 findValueOption 了。

我比较倾向于第二种。

@afc163
Copy link
Member

afc163 commented Jun 5, 2020

性能提升有多少,拿一下数据看看。

@kerm1it
Copy link
Member Author

kerm1it commented Jun 5, 2020

测试数据:10000个选项,初始选中5000个,测试点击关闭时选中框的响应时间:
优化前:

Jun-05-2020 14-12-14

优化后:

Jun-05-2020 14-14-59

优化前还有一个问题,就是选项和初始值很多时,一开始渲染都很费时间,需要等好久,优化后基本上点了后就能看到效果。

@afc163 afc163 merged commit 7f0dbd5 into react-component:master Jun 5, 2020
@afc163
Copy link
Member

afc163 commented Jun 5, 2020

稳妥起见,我发一个 minor,antd 里升级一下。

afc163 added a commit that referenced this pull request Jun 5, 2020
@afc163
Copy link
Member

afc163 commented Jun 5, 2020

改挂了,rc-tree-select 依赖了 rc-select minor 版本,使用了里面 getLabeledValue 和 generateSelector 方法。我先回滚了。

@kermit-xuan 再看看。

@afc163
Copy link
Member

afc163 commented Jun 5, 2020

image

afc163 added a commit that referenced this pull request Jun 5, 2020
@kerm1it
Copy link
Member Author

kerm1it commented Jun 5, 2020

@afc163 我看了要优化的话,必须要动 findValueOption,原来的这个方法查找时会遍历所有options,然后再遍历选中的值,最后得到结果,每次查询的复杂度是 O(n^2), 优化后的 findValueOption 是直接遍历选中的值从 Map 中查找,复杂度是 O(n)。动了 findValueOption,其他依赖于它的方法就得跟着变,例如 getLabeledValue, 除了 tree-select 还有别的组件依赖于 select 吗?不多的话我可以一次都改了

@yoyo837
Copy link
Member

yoyo837 commented Jun 5, 2020

还有AutoComplete 等,具体搜索一下代码

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.

5 participants