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

Conversation

gannunziata
Copy link
Contributor

Improved performance on Table with a lot of columns, avoiding internal use of _extends() on
_createColumn().

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

Choose a reason for hiding this comment

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

Can you move all these props to object literal and rename a11yProps to cellProps?

a11yProps.key = "Header-Col" + index;
a11yProps.className = classNames;
a11yProps.style = style;

Copy link
Contributor

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

Copy link
Owner

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

To be honest, I never intended (or imagined) Table to be used with more than a dozen columns. Anything so large as 150 would be better rendered as a Grid in my mind, because it would avoid the overhead of rendering a lot of column content that isn't visible (due to horizontal scrolling).

That being said, I don't really mind the micro-optimization in this case, so long as there is a clear inline comment explaining the motivation.

I also like the renaming suggestions @TrySound made.

@@ -523,7 +525,7 @@ export default class Table extends PureComponent {
? SortDirection.ASC
: SortDirection.DESC;

const onClick = event => {
const onClick = event => {
Copy link
Owner

Choose a reason for hiding this comment

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

nit: trailing whitespace

className={cn('ReactVirtualized__Table__rowColumn', className)}
style={style}
title={title}>
>
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.


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
Contributor

Choose a reason for hiding this comment

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

Move it back please

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

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
Contributor

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

@@ -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
Contributor

@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

@@ -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 😄

@@ -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


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.


// 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. 😄

@bvaughn bvaughn merged commit 7e961d1 into bvaughn:master Jan 13, 2018
@bvaughn
Copy link
Owner

bvaughn commented Jan 13, 2018

Thanks for the contribution!

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.

3 participants