Git Product home page Git Product logo

Comments (9)

guoyunhe avatar guoyunhe commented on July 19, 2024 1

image

@zombieJ 大致定位到三个最主要的性能消耗来源:

  1. @ant-design/cssinjsuseCacheToken()useCSSVarRegister() (19ms)
  2. @ant-design/colorsinputToRgb()toHex() (20ms)
  3. rc-motionCSSMotionCSSMotionList (13ms)

from ant-design.

zombieJ avatar zombieJ commented on July 19, 2024 1

<ConfigProvider> 没有加 theme 属性的话,是不是不需要有 cssinjs 相关的处理?

挖了一下。CP 中有一个 useStyle(iconPrefixCls, csp) 用来处理设置 iconPrefixCls 来改变的场景(因为 @ant-design/icons 并不被 antd 管理)。以至于 theme 的 token 计算被提前到了 CP(相当于原本 Button 渲染启动的 token 计算被提前了)。这个 token 计算时间无论是在 CP 中还是在 Button 中都是一次性的。所以在不变化主题时,这个损耗可以被无视掉。

截屏2024-06-07 14 29 34

(算过一次后,之后渲染只有 Button 元素自身的损耗)

from ant-design.

stackblitz avatar stackblitz commented on July 19, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

from ant-design.

zombieJ avatar zombieJ commented on July 19, 2024

聚合数据应该没这么慢才对,估计是什么地方有计算损耗。直接帮忙看看?~

from ant-design.

guoyunhe avatar guoyunhe commented on July 19, 2024

同样是使用 css-in-js 的 Material UI 的 ThemeProvider 要比 Ant Design 的 ConfigProvider 要快 60ms 左右:

Material UI
image

Ant Design
image

from ant-design.

afc163 avatar afc163 commented on July 19, 2024

@guoyunhe 帮忙排查一下具体问题所在吧,能来 PR 最好啦~

from ant-design.

guoyunhe avatar guoyunhe commented on July 19, 2024
  1. 初始化默认主题时,会将默认主题/自定义主题所有 color 实例化,这一过程过于耗时,但是实际上并不是所有的地方都需要实例化的 color 去进行颜色的计算。最好的情况肯定是避免实例化主题的颜色 token,在实际需要的时候再进行实例化,很多地方可以用 CSS 的 color-mix 来替代 JS color 计算。但这种改动不可避免地会产生破坏性变更,大佬们在 v6 考虑一下吧。
  2. css-in-js 我觉得还是性能瓶颈,优化算法可以缓解,但是不可能根除,v6 版本是否重回 less 或 sass?
  3. rc-motion 用了一些 rc-util 的函数 findDomNode, useState, 貌似效率不高,而且自身也逻辑太多。

from ant-design.

zombieJ avatar zombieJ commented on July 19, 2024

cssinjs 中获取完整的 design token 对业务里复用会比较方便,否则要做复杂计算(比如当 padding < 10 时使用样式 A,反之使用样式 B),开发者是无法从 css var 中感知的。此外,计算取整都是 cals 的弱项。

但是提到的完整主题计算的确是一个点,感觉可以想办法优化一下。

rc-motion 当子元素支持 dom ref 时不会调用 findDOMNode。逻辑多是需要的,rc-motion 对动画阶段进行了拆分从而可以让上游做更精细的管理。

from ant-design.

afc163 avatar afc163 commented on July 19, 2024

<ConfigProvider> 没有加 theme 属性的话,是不是不需要有 cssinjs 相关的处理?

from ant-design.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.