使用 react-virtualized 的 9 列滚动性能慢
Slow scrolling performance with 9 columns using react-virtualized
我正在使用 react-virtualized 与 material-ui table 单元格来创建 table 虚拟滚动,一切似乎都很好,但我偶尔会在向上和向下两个方向遍历 table 时性能下降。我打开一个开发控制台并在那里发现了一些警告 - 很多
[Violation] 'requestAnimationFrame' handler took ~116ms
和
[Violation] 'scroll' handler took ~150ms
条消息。
const MyTable: React.FunctionComponent<Props> = (props: Props) => {
//props, styles, table content fetching here
const headerRenderer = () => {
return (
<MyHeaderCell
styleClass={classes.headerCell}
content={"Header"}
/>
);
};
const cellRenderer = (rendererProps) => {
return (
<MyContentCell
styleClass={classes.tableCell}
rendererProps={rendererProps}
/>
);
};
const renderContent = () => {
return (
<InfiniteLoader
isRowLoaded={isRowLoaded}
loadMoreRows={loadMoretableItems}
rowCount={tableItemsQuantity}
>
{({ onRowsRendered}) => (
<AutoSizer>
{(sizerProps: IAutoSizerProps) => {
const { height, width } = sizerProps;
return (
<Table
onRowsRendered={onRowsRendered}
width={width}
height={height}
rowHeight={rowHeight}
rowCount={tableItems.length}
rowGetter={getCurrentRow}
overscanRowCount={5}
headerHeight={rowHeight}
rowClassName={classes.flexContainer}
noRowsRenderer={noRowsRenderer}
>
<Column
dataKey={nameof<MyTableItem>((o) => o.id)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop1)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop2)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop3)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop4)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop5)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop6)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop7)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop8)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
</Table>
);
}}
</AutoSizer>
)}
</InfiniteLoader>
);
};
return (
<Grid item container direction={"column"} className={classes.root}>
<h4>{Translate.getString("My Table Items")}</h4>
<Grid item className={classes.tableContainer}>
{renderContent}
<LoaderBlock isLoading={showTableLoader}/>
</Grid>
</Grid>
);
};
export { MyTable };
我可以做些什么来提高 table 的性能?
好吧,如果有人想知道如何解决这个问题,- 减少单元格和 header HTML 嵌套对我减少遍历 table 时的滞后有很大帮助。
Material UI components producing quite big elements tree -> react-virtualized 很难在弹出元素的同时渲染沉重的组件,所以你应该尽可能简单。
我正在使用 react-virtualized 与 material-ui table 单元格来创建 table 虚拟滚动,一切似乎都很好,但我偶尔会在向上和向下两个方向遍历 table 时性能下降。我打开一个开发控制台并在那里发现了一些警告 - 很多
[Violation] 'requestAnimationFrame' handler took ~116ms
和
[Violation] 'scroll' handler took ~150ms
条消息。
const MyTable: React.FunctionComponent<Props> = (props: Props) => {
//props, styles, table content fetching here
const headerRenderer = () => {
return (
<MyHeaderCell
styleClass={classes.headerCell}
content={"Header"}
/>
);
};
const cellRenderer = (rendererProps) => {
return (
<MyContentCell
styleClass={classes.tableCell}
rendererProps={rendererProps}
/>
);
};
const renderContent = () => {
return (
<InfiniteLoader
isRowLoaded={isRowLoaded}
loadMoreRows={loadMoretableItems}
rowCount={tableItemsQuantity}
>
{({ onRowsRendered}) => (
<AutoSizer>
{(sizerProps: IAutoSizerProps) => {
const { height, width } = sizerProps;
return (
<Table
onRowsRendered={onRowsRendered}
width={width}
height={height}
rowHeight={rowHeight}
rowCount={tableItems.length}
rowGetter={getCurrentRow}
overscanRowCount={5}
headerHeight={rowHeight}
rowClassName={classes.flexContainer}
noRowsRenderer={noRowsRenderer}
>
<Column
dataKey={nameof<MyTableItem>((o) => o.id)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop1)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop2)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop3)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop4)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop5)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop6)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop7)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
<Column
dataKey={nameof<MyTableItem>((o) => o.prop8)}
width={width}
headerClassName={clsx(classes.header, classes.column)}
headerRenderer={headerRenderer}
className={clsx(classes.header, classes.column)}
cellRenderer={cellRenderer}
/>
</Table>
);
}}
</AutoSizer>
)}
</InfiniteLoader>
);
};
return (
<Grid item container direction={"column"} className={classes.root}>
<h4>{Translate.getString("My Table Items")}</h4>
<Grid item className={classes.tableContainer}>
{renderContent}
<LoaderBlock isLoading={showTableLoader}/>
</Grid>
</Grid>
);
};
export { MyTable };
我可以做些什么来提高 table 的性能?
好吧,如果有人想知道如何解决这个问题,- 减少单元格和 header HTML 嵌套对我减少遍历 table 时的滞后有很大帮助。 Material UI components producing quite big elements tree -> react-virtualized 很难在弹出元素的同时渲染沉重的组件,所以你应该尽可能简单。