ant-design / antd-style

css-in-js library with antd v5 token system
https://ant-design.github.io/antd-style/
MIT License
219 stars 35 forks source link

🐛[BUG] useStyles和useTheme的性能问题 #173

Open shanhexi opened 3 hours ago

shanhexi commented 3 hours ago

🐛 bug 描述

在我的基础组件Iconfont中我使用了useStyles,这个icon被应用到了antd 虚拟滚动的tree中, 现在我遇到了性能问题,每个icon的渲染都会执行useStyles,我看到createStylesFactory这个方法的执行时间在20ms,这对虚拟滚动的场景应该是不能接受的。 我觉得这个问题同 #158

📷 复现步骤

🏞 期望结果

可以优化useStyles的时间,或者能不能有一个单例的useStyles,没必要每个组件都要去执行useStyles

💻 复现代码

可复现demo: https://codesandbox.io/p/sandbox/frosty-chatelet-j23j8m?file=%2Fsrc%2FDemo.tsx%3A10%2C1

© 版本信息

🚑 其他信息

image image
arvinxx commented 3 hours ago

嗯,#158 的问题的确存在。上次看过一次,一下子没找到解决方案,最近有空的时候再研究下怎么解比较好。核心应该还是因为引用不同造成了 re-render

shanhexi commented 2 hours ago

嗯,#158 的问题的确存在。上次看过一次,一下子没找到解决方案,最近有空的时候再研究下怎么解比较好。核心应该还是因为引用不同造成了 re-render

好的谢谢,还有个问题就是主题色切换反应有些慢,这个有的解吗,包括lobechat也有这个问题,在页面更复杂的时候这个时间可能会更久。