From c1f94be892649b99def9ffe9c1c9603afdb15a4c Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Mon, 20 Jul 2026 15:36:14 +0100 Subject: [PATCH 1/2] perf: reuse accessRows function We were previously allocating an arrow function per call with its own scope. If we move this to module level and pass `table` in, we can re-use the same function allocated once. --- .../src/core/row-models/createCoreRowModel.ts | 92 ++++++++++--------- 1 file changed, 50 insertions(+), 42 deletions(-) diff --git a/packages/table-core/src/core/row-models/createCoreRowModel.ts b/packages/table-core/src/core/row-models/createCoreRowModel.ts index 1876b066d5..00ff950813 100644 --- a/packages/table-core/src/core/row-models/createCoreRowModel.ts +++ b/packages/table-core/src/core/row-models/createCoreRowModel.ts @@ -30,6 +30,55 @@ export function createCoreRowModel< } } +function accessRows( + table: Table_Internal, + rowModel: RowModel, + originalRows: ReadonlyArray, + depth = 0, + parentRow?: Row, +): Array> { + const rows = [] as Array> + + for (let i = 0; i < originalRows.length; i++) { + const originalRow = originalRows[i]! + // Make the row + const row = constructRow( + table, + table.getRowId(originalRow, i, parentRow), + originalRow, + i, + depth, + undefined, + parentRow?.id, + ) + + // Keep track of every row in a flat array + rowModel.flatRows.push(row) + // Also keep track of every row by its ID + rowModel.rowsById[row.id] = row + // Push table row into parent + rows.push(row) + + // Get the original subrows + if (table.options.getSubRows) { + row.originalSubRows = table.options.getSubRows(originalRow, i) + + // Then recursively access them + if (row.originalSubRows?.length) { + row.subRows = accessRows( + table, + rowModel, + row.originalSubRows, + depth + 1, + row, + ) + } + } + } + + return rows +} + function _createCoreRowModel< TFeatures extends TableFeatures, TData extends RowData, @@ -47,48 +96,7 @@ function _createCoreRowModel< rowsById: makeObjectMap(), } - const accessRows = ( - originalRows: ReadonlyArray, - depth = 0, - parentRow?: Row, - ): Array> => { - const rows = [] as Array> - - for (let i = 0; i < originalRows.length; i++) { - const originalRow = originalRows[i]! - // Make the row - const row = constructRow( - table, - table.getRowId(originalRow, i, parentRow), - originalRow, - i, - depth, - undefined, - parentRow?.id, - ) - - // Keep track of every row in a flat array - rowModel.flatRows.push(row) - // Also keep track of every row by its ID - rowModel.rowsById[row.id] = row - // Push table row into parent - rows.push(row) - - // Get the original subrows - if (table.options.getSubRows) { - row.originalSubRows = table.options.getSubRows(originalRow, i) - - // Then recursively access them - if (row.originalSubRows?.length) { - row.subRows = accessRows(row.originalSubRows, depth + 1, row) - } - } - } - - return rows - } - - rowModel.rows = accessRows(data) + rowModel.rows = accessRows(table, rowModel, data) return rowModel } From 61be2628512919a569cee26db39089429a0a200c Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Mon, 20 Jul 2026 15:52:03 +0100 Subject: [PATCH 2/2] perf: avoid allocating array for key compute --- packages/table-core/src/core/rows/coreRowsFeature.utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/table-core/src/core/rows/coreRowsFeature.utils.ts b/packages/table-core/src/core/rows/coreRowsFeature.utils.ts index cf41cf7d67..e5ac4fa91a 100644 --- a/packages/table-core/src/core/rows/coreRowsFeature.utils.ts +++ b/packages/table-core/src/core/rows/coreRowsFeature.utils.ts @@ -311,7 +311,7 @@ export function table_getRowId< ) { return ( table.options.getRowId?.(originalRow, index, parent) ?? - `${parent ? [parent.id, index].join('.') : index}` + (parent ? `${parent.id}.${index}` : String(index)) ) }