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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions source/Table/Table.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/** @flow */

import type {CellPosition} from '../Grid';
// import type {CellPosition} from '../Grid';

import cn from 'classnames';
import Column from './Column';
import PropTypes from 'prop-types';
import React, {PureComponent} from 'react';
import {findDOMNode} from 'react-dom';
import Grid, {accessibilityOverscanIndicesGetter} from '../Grid';
import type {CellPosition} from '../Grid';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move it back please


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 +428,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,24 +446,20 @@ export default class Table extends PureComponent {

const style = this._cachedColumnStyles[columnIndex];

const title = typeof renderedCell === 'string' ? renderedCell : null;
const colTitle = 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: colTitle,
};

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

a11yProps.key = "Row" + rowIndex + "-" + "Col" + columnIndex;
a11yProps.className = cn('ReactVirtualized__Table__rowColumn', className);
a11yProps.style = style;
a11yProps.title = title;

return (
<div
{...a11yProps}
{...columnProps}
>
Copy link
Owner

Choose a reason for hiding this comment

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

Looks like the crux of this fix is to avoid generating sub-optimal React.createElement boilerplate with an added function call and for-loop. But that's not obvious at a glance, and might regress later.

I'd suggest adding a comment about why it's important not to mix inline props and spread props.

{renderedCell}
</div>
Expand All @@ -482,6 +481,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 @@ -509,10 +509,10 @@ export default class Table extends PureComponent {
sortDirection,
});

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


let chOnClick, cOnKeyDown, chTabIndex, ariaSort, ariaLabel;
Copy link
Owner

Choose a reason for hiding this comment

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

What does "ch0n" and "c0n" and "ch" mean?

RV doesn't have an official styleguide, but if it did- "avoid abbreviated variable names" would be one of the first things I'd write. Please rename these.


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 @@ -540,28 +540,33 @@ export default class Table extends PureComponent {
}
};

a11yProps['aria-label'] = column.props['aria-label'] || label || dataKey;
a11yProps.tabIndex = 0;
a11yProps.onClick = onClick;
a11yProps.onKeyDown = onKeyDown;
ariaLabel = column.props['aria-label'] || label || dataKey;
chTabIndex = 0;
chOnClick = onClick;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you move these values to object literal?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Never mind. Didn't see condition

chOnKeyDown = onKeyDown;
}

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

if (id) {
a11yProps.id = id;
}

a11yProps.key = "Header-Col" + index;
a11yProps.className = classNames;
a11yProps.style = style;
const colHeaderProps = {
id: id || undefined,
role: 'columnheader',
'aria-label': ariaLabel,
'aria-sort': ariaSort,
tabIndex: chTabIndex,
onClick: chOnClick,
onKeyDown: chOnKeyDown,
key: "Header-Col" + index,
className: classNames,
style: style,
title: title || null
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same move and rename to headerProps

return (
<div
{...a11yProps}>
{...colHeaderProps}>
{renderedHeader}
</div>
);
Expand Down