Skip to content
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

Improved performance on Table with a lot of columns (> 150) #942

Merged
merged 7 commits into from Jan 13, 2018
Merged
69 changes: 41 additions & 28 deletions source/Table/Table.js
Expand Up @@ -8,6 +8,7 @@ import PropTypes from 'prop-types';
import React, {PureComponent} from 'react';
import {findDOMNode} from 'react-dom';
import Grid, {accessibilityOverscanIndicesGetter} from '../Grid';

Copy link
Collaborator

@TrySound TrySound Jan 12, 2018

Choose a reason for hiding this comment

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

remove newline

import defaultRowRenderer from './defaultRowRenderer';
import defaultHeaderRowRenderer from './defaultHeaderRowRenderer';
import SortDirection from './SortDirection';
Expand Down Expand Up @@ -426,6 +427,7 @@ export default class Table extends PureComponent {
className,
columnData,
dataKey,
title,
Copy link
Owner

Choose a reason for hiding this comment

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

nit: Alpha sort prop-lists like this 😄

id,
} = column.props;

Expand All @@ -443,23 +445,24 @@ export default class Table extends PureComponent {

const style = this._cachedColumnStyles[columnIndex];

const title = typeof renderedCell === 'string' ? renderedCell : null;
const columnTitle = title ? title : (typeof renderedCell === 'string' ? renderedCell : null);

const a11yProps = {
const columnProps = {
role: 'gridcell',
'aria-describedby': id || undefined,
key: "Row" + rowIndex + "-" + "Col" + columnIndex,
className: cn('ReactVirtualized__Table__rowColumn', className),
style: style,
title: columnTitle,
};

if (id) {
a11yProps['aria-describedby'] = id;
}


// NOTE: is important to NOT mixin inline property and spread properties,
// since internally REACT clone property object to adds inline property
// and slow down performances
Copy link
Owner

Choose a reason for hiding this comment

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

The wording of this comment (and the one below) confuse me. I don't think this has anything to do with "React internals" (unless I'm misunderstanding something). I believe this change is being made to avoid the overhead added by the babel-runtime extends method.

Before this change:

return _react2.default.createElement(
  'div',
  (0, _extends3.default)({}, a11yProps, {
    key: 'Row' + rowIndex + '-Col' + columnIndex,
    className: (0, _classnames2.default)('ReactVirtualized__Table__rowColumn', className),
    style: style,
    title: title }),
  renderedCell
);

After this change:

return (
  <div
    {...columnProps}
   >
    {renderedCell}
  </div>
);

Copy link
Owner

Choose a reason for hiding this comment

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

That being said, I'm happy to update the wording of the comment myself, so don't worry about it. 😄

return (
<div
{...a11yProps}
key={`Row${rowIndex}-Col${columnIndex}`}
className={cn('ReactVirtualized__Table__rowColumn', className)}
style={style}
title={title}>
{...columnProps}
>
{renderedCell}
</div>
);
Expand All @@ -480,6 +483,7 @@ export default class Table extends PureComponent {
headerRenderer,
id,
label,
title,
Copy link
Owner

Choose a reason for hiding this comment

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

Another props-sort nit

columnData,
defaultSortDirection,
} = column.props;
Expand Down Expand Up @@ -507,10 +511,10 @@ export default class Table extends PureComponent {
sortDirection,
});

const a11yProps = {
role: 'columnheader',
};


let headerOnClick, headerOnKeyDown, headerTabIndex, headerAriaSort, headerAriaLabel;

if (sortEnabled || onHeaderClick) {
// If this is a sortable header, clicking it should update the table data's sorting.
const isFirstTimeSort = sortBy !== dataKey;
Expand Down Expand Up @@ -538,27 +542,36 @@ export default class Table extends PureComponent {
}
};

a11yProps['aria-label'] = column.props['aria-label'] || label || dataKey;
a11yProps.tabIndex = 0;
a11yProps.onClick = onClick;
a11yProps.onKeyDown = onKeyDown;
headerAriaLabel = column.props['aria-label'] || label || dataKey;
headerTabIndex = 0;
headerOnClick = onClick;
headerOnKeyDown = onKeyDown;
}

if (sortBy === dataKey) {
a11yProps['aria-sort'] =
sortDirection === SortDirection.ASC ? 'ascending' : 'descending';
headerAriaSort = sortDirection === SortDirection.ASC ? 'ascending' : 'descending';
}

if (id) {
a11yProps.id = id;
}
const headerProps = {
id: id || undefined,
role: 'columnheader',
'aria-label': headerAriaLabel,
'aria-sort': headerAriaSort,
tabIndex: headerTabIndex,
onClick: headerOnClick,
onKeyDown: headerOnKeyDown,
key: "Header-Col" + index,
className: classNames,
style: style,
title: title || null
};

// NOTE: is important to NOT mixin inline property and spread properties,
// since internally REACT clone property object to adds inline property
// and slow down performances
return (
<div
{...a11yProps}
key={`Header-Col${index}`}
className={classNames}
style={style}>
{...headerProps}>
{renderedHeader}
</div>
);
Expand Down