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

Optimizing column/row cache update mechanism. #676

Merged
merged 2 commits into from
May 8, 2017
Merged
Changes from all commits
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
25 changes: 18 additions & 7 deletions source/CellMeasurer/CellMeasurerCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,29 @@ export default class CellMeasurerCache {
// :columnWidth and :rowHeight are derived based on all cells in a column/row.
// Pre-cache these derived values for faster lookup later.
// Reads are expected to occur more frequently than writes in this case.
const columnKey = this._keyMapper(0, columnIndex)
const rowKey = this._keyMapper(rowIndex, 0)
let columnWidth = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

There is precomputed value from constructor for minWidth.

let columnWidth = this._minWidth;

for (let i = 0; i < this._rowCount; i++) {
columnWidth = Math.max(columnWidth, this.getWidth(i, columnIndex))
if (this._hasFixedWidth) {
// if has fixed width columns, no need to calculate width for each row
Copy link
Contributor

Choose a reason for hiding this comment

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

If the hasFixedWidth is true then cell measurer cache can only use defaultWidth. Or you can substitute this block with getWidth function. Look at the implementation of getWidth it is basicly doing the same thing as you in this block of code.

columnWidth = this.defaultWidth;
// or
columnWidth = this.getWidth(rowIndex, columnIndex);

Copy link
Owner

Choose a reason for hiding this comment

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

This is a reasonable point!

I believe we can skip doing any work in the fixed-width or fixed-height case. It's expected that defaultWidth or defaultHeight will be used in those cases so there isn't really any need to even set the value. 😁

columnWidth = this._columnWidthCache[columnKey] || columnWidth
columnWidth = Math.max(columnWidth, this.getWidth(rowIndex, columnIndex))
} else {
for (let i = 0; i < this._rowCount; i++) {
columnWidth = Math.max(columnWidth, this.getWidth(i, columnIndex))
}
}
let rowHeight = 0
Copy link
Contributor

@marcelmokos marcelmokos May 7, 2017

Choose a reason for hiding this comment

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

There is precomputed value from constructor for minHeight.

let rowHeight = this._minHeight;

for (let i = 0; i < this._columnCount; i++) {
rowHeight = Math.max(rowHeight, this.getHeight(rowIndex, i))
if (this._hasFixedHeight) {
// if has fixed height rows, no need to calculate height for each column
Copy link
Contributor

Choose a reason for hiding this comment

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

If the hasFixedHeight is true then cell measurer cache can only use defaultHeight. Or you can substitute this block with getHeight function. Look at the implementation of getHeight it is basically doing the same thing as you in this block of code.

rowHeight = this.defaultHeight;
// or
rowHeight = this. getHeight(rowIndex, columnIndex);

rowHeight = this._rowHeightCache[rowKey] || rowHeight
rowHeight = Math.max(rowHeight, this.getHeight(rowIndex, columnIndex))
} else {
for (let i = 0; i < this._columnCount; i++) {
rowHeight = Math.max(rowHeight, this.getHeight(rowIndex, i))
}
}

const columnKey = this._keyMapper(0, columnIndex)
const rowKey = this._keyMapper(rowIndex, 0)

this._columnWidthCache[columnKey] = columnWidth
this._rowHeightCache[rowKey] = rowHeight
}
Expand Down