ant-design / ant-design-colors

:art: Color Palettes Calculator of Ant Design
https://ant.design/docs/spec/colors
MIT License
652 stars 79 forks source link

大幅提升颜色预设的运行时性能 #91

Closed guoyunhe closed 3 months ago

guoyunhe commented 3 months ago

目前的实现会在运行时计算颜色,大量调用 hsv <-> rgb 转换会成为性能瓶颈。即使你只用了一种预设也会将所有的预设都计算出来。

此 PR 则是在编译时就将所有预设计算出来,算是一种用空间换时间的做法。本包的体积会有所增加。但由于支持 tree shaking,且实际在 antd 中只会引用少数几个 preset, 并不会明显增加 antd 的打包体积。

socket-security[bot] commented 3 months ago

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/tsx@4.16.0 Transitive: environment, filesystem, network, shell +24 203 MB hirokiosame
npm/vitest@1.6.0 environment, eval Transitive: filesystem, network, shell, unsafe +63 10.6 MB vitestbot

View full report↗︎

afc163 commented 3 months ago

有没有性能对比,能在这个项目里加个 benchmark 做 ci 对比么?

guoyunhe commented 3 months ago

@afc163 新增 benchmark,预编译的性能是运行时计算的1万倍左右

image

CI 不太好做,因为 GitHub CI 是虚拟机,无法保证每次 CI 分配到的 CPU 资源是一致的。benchmark 只有在相同环境下跑两份代码才有比较意义。

afc163 commented 3 months ago

覆盖率掉的比较厉害