-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
There was a problem hiding this comment.
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.