Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolves depsEqual performance issues (#2577) #2578

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

caorushizi
Copy link
Contributor

[English Template / 英文模板]

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

#2577 [useDeepCompareEffect] 在组件re-render时进行depsEqual造成性能问题

💡 需求背景和解决方案

背景: 在更新 State 为相同数据后,depsEqual 判断依赖数据没有变化,ref.current 的值没有进行更新,导致后续页面上组件因为其他State/Props进行re-render时,useDeepCompareEffect会一直进行深度对比,导致严重的性能问题(因为真实数据层级较多)。

解决方案: 无论 depsEqual 相同或者不同,都要记录上次 render 的依赖的变化。具体执行逻辑参考 codesanbox 中的 newCreateDeepCompareEffect 。

复现步骤

  1. 点击页面中的【重新设置相同的数据】
  2. 点击【重新渲染】按钮
  3. 观察控制台中的输出

createDeepCompareEffect 的 log 如下:
image

useDeepCompareEffectNew 的 log 如下:
image

可以观察到,depsEqual 执行的判断明显减少

📝 更新日志

语言 更新描述
🇺🇸 英文 Resolves depsEqual performance issues when references dependent on useDeepCompareEffect change
🇨🇳 中文 解决 useDeepCompareEffect 依赖的引用变化时 depsEqual 的性能问题

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

@CLAassistant
Copy link

CLAassistant commented Jun 23, 2024

CLA assistant check
All committers have signed the CLA.

@caorushizi caorushizi marked this pull request as draft June 25, 2024 02:09
@caorushizi caorushizi marked this pull request as ready for review June 25, 2024 02:10
@caorushizi
Copy link
Contributor Author

@crazylxr 可否帮忙看下~

@crazylxr crazylxr merged commit d92f995 into alibaba:master Jul 8, 2024
1 check passed
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.

3 participants