Skip to content

Conversation

curly210102
Copy link
Contributor

问题描述:设置 scroll.x,resize 或者切换侧边栏时,卡顿明显。Ref: ant-design/ant-design#27775
解决方式:单个 ResizeObserver 实例 observe 所有列,支持在一个 Task 周期批量处理 Resize 引发的 Update
优化结果:固定栏平铺-折叠切换,所需用时 6646.2ms ➜ 1080.8 ms
具体分析#701 (comment)

@vercel
Copy link

vercel bot commented Nov 25, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/react-component/table/DqLNNuQtfdnCNJWujSRePTh5FHQf
✅ Preview: https://table-git-fork-curly210102-performance-r-b95bad-react-component.vercel.app

@zombieJ
Copy link
Member

zombieJ commented Nov 29, 2021

好了,添加了 ResizeObserver.Collection。可以一次性收集所有子 ResizeObserver 的变化:
https://resize-observer-react-component.vercel.app/demo/collection

@codecov
Copy link

codecov bot commented Nov 30, 2021

Codecov Report

Merging #706 (018c4a8) into master (b0858ca) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #706   +/-   ##
=======================================
  Coverage   99.67%   99.68%           
=======================================
  Files          32       33    +1     
  Lines         935      951   +16     
  Branches      284      285    +1     
=======================================
+ Hits          932      948   +16     
  Misses          3        3           
Impacted Files Coverage Δ
src/Body/MeasureCell.tsx 100.00% <100.00%> (ø)
src/Body/MeasureRow.tsx 100.00% <100.00%> (ø)
src/Body/index.tsx 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b0858ca...018c4a8. Read the comment docs.

onColumnResizeRef.current = onColumnResize;
const debounceColumnResize = React.useMemo(
() =>
debounce(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debounce 可以去掉了,ResizeObserver.Collection 里做过一次了~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emmm...看了下源码似乎没有发现,这里的 debounce 是处理连续调整 table 大小导致多次触发 resize callback 的情况哦

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen.Recording.2021-11-30.at.11.18.00.AM.mov

例如拖动调整大小,单纯用 ResizeObserver.Collection 卡顿还是挺明显的

<ResizeObserver.Collection
  onBatchResize={infoList => {
    infoList.forEach(({ data, size }) => {
      onColumnResize(data, size.offsetWidth);
    });
  }}
></ResizeObserver.Collection>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我的想法是渲染同步更重要一些,所以在 onBatchResize 里是通过 Promise 做帧的同步。这边的 debounce 做 1200 是渲染快了,但是同步慢了。
这样,做个折中用 https://github.com/react-component/util/blob/master/src/raf.ts 做 2 帧 delay 好了。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,虽然没有 debounce 那么丝滑,相较于单帧渲染还是自然一些。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请问是因为表格body添加了MesureRow而表格头没有添加,导致的上下宽度改变不同步吗? ant-design/ant-design#33545

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@curly210102 看看上面这个问题?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@curly210102 结论是啥?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以去掉两帧的延迟

@zombieJ zombieJ merged commit 170a87d into react-component:master Nov 30, 2021
@zombieJ
Copy link
Member

zombieJ commented Nov 30, 2021

+ rc-table@7.20.5

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.

4 participants