-
Notifications
You must be signed in to change notification settings - Fork 580
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
Optimize shouldComponentUpdate #96
Conversation
给力,搞个性能对比看看效果? |
@@ -4,6 +4,7 @@ import TableHeader from './TableHeader'; | |||
import { measureScrollbar, debounce } from './utils'; | |||
import shallowequal from 'shallowequal'; | |||
import addEventListener from 'rc-util/lib/Dom/addEventListener'; | |||
import ColumnManager from './ColumnManager'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文件名大小写。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
调整了。
简单测试了下,用下面的代码渲染 100 条数据。 const React = require('react');
const ReactDOM = require('react-dom');
const Table = require('rc-table');
require('rc-table/assets/index.less');
const columns = [{
title: '姓名',
dataIndex: 'name',
width: 150,
fixed: 'left',
key: 'title',
}, {
title: '年龄',
dataIndex: 'age',
width: 150,
key: 'age',
}, {
title: '住址',
dataIndex: 'address',
key: 'address',
}];
const data = [];
for (let i = 0; i < 100; i++) {
data.push({
key: i,
name: `李大嘴${i}`,
age: 32,
address: `西湖区湖底公园${i}号`,
});
}
ReactDOM.render(<Table columns={columns} data={data} />, document.getElementById('__react-content')); 在 Table 的 render 第一行加上 不加这个 patch 前鼠标 hover 一次 Table render 一次的时间大概是 60ms 左右,加上这个 patch 后大概在 15-20ms。然后顺便试下了 #95 的方案,因为这个方案在 hover 的时候 Table 不需要渲染,所以渲染 hover 那行 TableRow 只要零点几毫秒。 @afc163 另外你们之前有没有写 React benchmark 的方案? |
感觉 #95 的方案还是可以考虑下的。 |
那 #95 也合并了好了,发个 5.1 |
对一行 row 做一次 hover 和 unhover,Perf 的数据: master每行 TableRow 都被重新渲染,总共渲染了400 次。 这个 PR只有 hover 的那行 TableRow 重新渲染了,但是渲染 Table 还是需要 20ms 左右。 #95只渲染了 TableRow,只要零点几毫秒。 |
@afc163 没问题合并了? |
请问这个columns里面的render内容如果用组件代替的话,但是每次切换页数,像@yesmeck说的shouldComponent会重新走一遍,确切的说是组件会重新加载一次因为componentDidMount也执行了,这个问题是2016年提出来的,现在是2019/12 我的antd版本是antd:"^3.18.1",我测了一下还是有这个问题,这个问题解决了么现在,可以回复一下么,万分感谢 |
这样改完后发现 #95 其实不需要了, shouldComponentUpdate 可以正常工作了。