From a0e1cfc0683ed768a5d84e31562aeebf2e30acef Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Mon, 20 Jul 2026 15:37:29 +0100 Subject: [PATCH 1/2] perf: pre-compute instance init functions When we construct a row, we iterate over the table's features and initialise any which have an `initRowInstanceData`. This is expensive since most don't have such a method. We actually know when we construct the table which features have this method. This changes the table construction to store the initialisers up front so when we create a row, we can just iterate the already known initialisers. --- packages/table-core/src/core/rows/constructRow.ts | 6 +++--- packages/table-core/src/core/table/constructTable.ts | 10 ++++++++++ .../src/core/table/coreTablesFeature.types.ts | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/table-core/src/core/rows/constructRow.ts b/packages/table-core/src/core/rows/constructRow.ts index 663f346962..a950f00505 100644 --- a/packages/table-core/src/core/rows/constructRow.ts +++ b/packages/table-core/src/core/rows/constructRow.ts @@ -59,9 +59,9 @@ export const constructRow = < row.subRows = subRows ?? [] // Initialize instance-specific data (e.g., caches) for features that need it - const features = Object.values(table._features) - for (let i = 0; i < features.length; i++) { - features[i]!.initRowInstanceData?.(row) + const initFns = table._rowInstanceInitFns! + for (let i = 0; i < initFns.length; i++) { + initFns[i]!(row as Row) } return row as Row diff --git a/packages/table-core/src/core/table/constructTable.ts b/packages/table-core/src/core/table/constructTable.ts index 3a2f648966..520a33303a 100644 --- a/packages/table-core/src/core/table/constructTable.ts +++ b/packages/table-core/src/core/table/constructTable.ts @@ -68,6 +68,16 @@ export function constructTable< const featuresList: Array = Object.values(table._features) + const rowInstanceInitFns: Array< + NonNullable + > = [] + for (const feature of featuresList) { + if (feature.initRowInstanceData) { + rowInstanceInitFns.push(feature.initRowInstanceData) + } + } + table._rowInstanceInitFns = rowInstanceInitFns + const defaultOptions = featuresList.reduce((obj, feature) => { return Object.assign(obj, feature.getDefaultTableOptions?.(table)) }, {}) as TableOptions diff --git a/packages/table-core/src/core/table/coreTablesFeature.types.ts b/packages/table-core/src/core/table/coreTablesFeature.types.ts index 8570660430..80afe099e7 100644 --- a/packages/table-core/src/core/table/coreTablesFeature.types.ts +++ b/packages/table-core/src/core/table/coreTablesFeature.types.ts @@ -5,6 +5,7 @@ import type { RowModelFns } from '../../types/RowModelFns' import type { RowData, Updater } from '../../types/type-utils' import type { IsAny, + TableFeature, TableFeatures, ValidateFeatureSlots, } from '../../types/TableFeatures' @@ -188,6 +189,10 @@ export interface Table_CoreProperties< * Prototype cache for Row objects - shared by all rows in this table */ _rowPrototype?: object + /** + * Cache of the `initRowInstanceData` functions for features that define one. + */ + _rowInstanceInitFns?: Array> /** * The readonly derived atoms for each `TableState` slice. Each derives from * its corresponding `baseAtom` plus, optionally, a per-slice external atom or From a0057d30a2c1f0a07c4a7bafe160c07276cc9c30 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Mon, 20 Jul 2026 16:10:40 +0100 Subject: [PATCH 2/2] fix(table-core): bind initialiser to feature Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- packages/table-core/src/core/table/constructTable.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/table-core/src/core/table/constructTable.ts b/packages/table-core/src/core/table/constructTable.ts index 520a33303a..2d706c8234 100644 --- a/packages/table-core/src/core/table/constructTable.ts +++ b/packages/table-core/src/core/table/constructTable.ts @@ -73,7 +73,7 @@ export function constructTable< > = [] for (const feature of featuresList) { if (feature.initRowInstanceData) { - rowInstanceInitFns.push(feature.initRowInstanceData) + rowInstanceInitFns.push(feature.initRowInstanceData.bind(feature)) } } table._rowInstanceInitFns = rowInstanceInitFns