Skip to content

Commit

Permalink
perf: replace Object assign with direct mutation in feature code (#5048)
Browse files Browse the repository at this point in the history
Object.assign is very performance Heavy, when compared with direct assignment, and can easily be replaced with direct mutations in the creational functions. Since theese get called *a lot* when the data changes, especially with large amounts of data, the performance impact is quite huge.

Co-authored-by: Günter Manz <[email protected]>
  • Loading branch information
retnag and Günter Manz committed Sep 10, 2023
1 parent a05c7f8 commit 605e13e
Show file tree
Hide file tree
Showing 15 changed files with 1,846 additions and 1,964 deletions.
13 changes: 5 additions & 8 deletions packages/table-core/src/core/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ export function createCell<TData extends RowData, TValue>(
}

table._features.forEach(feature => {
Object.assign(
cell,
feature.createCell?.(
cell as Cell<TData, TValue>,
column,
row as Row<TData>,
table
)
feature.createCell?.(
cell as Cell<TData, TValue>,
column,
row as Row<TData>,
table
)
}, {})

Expand Down
6 changes: 3 additions & 3 deletions packages/table-core/src/core/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ export function createColumn<TData extends RowData, TValue>(
),
}

column = table._features.reduce((obj, feature) => {
return Object.assign(obj, feature.createColumn?.(column, table))
}, column)
for (const feature of table._features) {
feature.createColumn?.(column, table)
}

// Yes, we have to convert table to uknown, because we know more than the compiler here.
return column as Column<TData, TValue>
Expand Down
Loading

0 comments on commit 605e13e

Please sign in to comment.