feat: 修改derivedStateOf 方案 并添加方案4 LaunchedEffect + collect + distinctU…#3
Open
p1ayer1 wants to merge 1 commit into
Open
feat: 修改derivedStateOf 方案 并添加方案4 LaunchedEffect + collect + distinctU…#3p1ayer1 wants to merge 1 commit into
p1ayer1 wants to merge 1 commit into
Conversation
…ntilChanged`(保护父组件自身)
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.
在运行kuikly-recomposition-analyzer/SKILL后生成的报告中 关于
derivedStateOf派生局部状态相关优化建议生成会有问题🔴 [高] DiscoverFilterTabBar — 双重重组未完全消除,avg 耗时降低
重组次数:84 次
平均单次耗时:18.61ms(最大 383ms)(v3:37.22ms → 降幅 50%)
总耗时:1,563ms(v3:1,861ms → 降幅 16%)
双重重组帧:35 帧(归一化后 1.33/100帧,v3 为 3.50/100帧,降幅 62%)
问题描述:
删除
dismissDrop()后,dropViewModel.uiState触发的双重重组减少,但仍有 35 帧出现双重重组。新的触发来源是filterViewModel.uiState(22 次)和图片加载 State(24 次)。根因:
filterViewModel.uiState在游戏 tab 切换时更新(getSearchOption返回),同帧内dropViewModel.uiState也在更新(syncMenuData),两个 State 在同帧内各触发一次,导致双重重组。图片加载 State 触发的双重重组是新出现的,需要进一步排查。优化建议:
将
DiscoverFilterTabBar内部的filterViewModel.uiState订阅改为精准订阅,只读取confirmedCount:其中val confirmedCount by remember { derivedStateOf { filterViewModel.uiState.value.confirmedCount } } 这条是错误建议,原理已在代码改动说说明。
修改skill后优化建议如下
优化建议:
将
filterViewModel.uiState的订阅从collectAsState()改为LaunchedEffect + map + distinctUntilChanged,只在confirmedCount真正变化时才触发DiscoverFilterTabBar重组: