Skip to content

perf(table-core): pre-compute instance init functions#6446

Open
43081j wants to merge 2 commits into
TanStack:betafrom
43081j:jg/pre-compute-instance-inits
Open

perf(table-core): pre-compute instance init functions#6446
43081j wants to merge 2 commits into
TanStack:betafrom
43081j:jg/pre-compute-instance-inits

Conversation

@43081j

@43081j 43081j commented Jul 20, 2026

Copy link
Copy Markdown

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.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

Summary by CodeRabbit

  • Performance
    • Improved table row creation efficiency by precomputing and caching per-feature row instance initialization callbacks.
    • Row instance setup now reuses the cached initialization steps rather than iterating feature callbacks during each row build.
    • Kept row construction behavior the same, including existing prototype retrieval, caches, and default sub-row handling.

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.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 886e861d-1636-4fe8-a23e-b685ba94a712

📥 Commits

Reviewing files that changed from the base of the PR and between a0e1cfc and a0057d3.

📒 Files selected for processing (1)
  • packages/table-core/src/core/table/constructTable.ts

📝 Walkthrough

Walkthrough

constructTable caches enabled feature row-initialization callbacks on the table. constructRow uses that cache to initialize each new row, and the core table properties type defines the cache.

Changes

Row instance initialization

Layer / File(s) Summary
Cache feature initialization callbacks
packages/table-core/src/core/table/coreTablesFeature.types.ts, packages/table-core/src/core/table/constructTable.ts
Adds the typed _rowInstanceInitFns cache and populates it from enabled feature hooks during table construction.
Invoke cached callbacks for new rows
packages/table-core/src/core/rows/constructRow.ts
Uses cached initialization callbacks when constructing each row instead of scanning table features.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant constructTable
  participant featuresList
  participant table
  participant constructRow
  constructTable->>featuresList: collect initRowInstanceData callbacks
  featuresList-->>constructTable: callbacks
  constructTable->>table: store _rowInstanceInitFns
  constructRow->>table: read cached callbacks
  table-->>constructRow: callbacks
  constructRow->>constructRow: invoke callbacks for new row
Loading

Possibly related PRs

Suggested reviewers: kevinvandy

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: precomputing row instance initialization functions for table-core.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/table-core/src/core/table/constructTable.ts`:
- Around line 71-79: Update the row-instance hook caching in the feature
iteration to preserve each feature as the callback receiver. Bind each
`initRowInstanceData` hook to its owning feature, or cache the feature/function
pair and invoke it with `feature` as `this` when populating
`table._rowInstanceInitFns`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 35662c39-160b-4be9-bd3e-d6605d667753

📥 Commits

Reviewing files that changed from the base of the PR and between 209699f and a0e1cfc.

📒 Files selected for processing (3)
  • packages/table-core/src/core/rows/constructRow.ts
  • packages/table-core/src/core/table/constructTable.ts
  • packages/table-core/src/core/table/coreTablesFeature.types.ts

Comment thread packages/table-core/src/core/table/constructTable.ts
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@KevinVandy

Copy link
Copy Markdown
Member

I like this change, and I will properly review this in a few days.

@nx-cloud

nx-cloud Bot commented Jul 21, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit a0057d3

Command Status Duration Result
nx affected --targets=test:eslint,test:sherif,t... ✅ Succeeded 7m 27s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 48s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-21 04:53:41 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jul 21, 2026

Copy link
Copy Markdown
More templates

@tanstack/alpine-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/alpine-table@6446

@tanstack/angular-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/angular-table@6446

@tanstack/angular-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/angular-table-devtools@6446

@tanstack/ember-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/ember-table@6446

@tanstack/lit-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/lit-table@6446

@tanstack/match-sorter-utils

npm i https://pkg.pr.new/TanStack/table/@tanstack/match-sorter-utils@6446

@tanstack/preact-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/preact-table@6446

@tanstack/preact-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/preact-table-devtools@6446

@tanstack/react-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table@6446

@tanstack/react-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table-devtools@6446

@tanstack/solid-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table@6446

@tanstack/solid-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table-devtools@6446

@tanstack/svelte-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/svelte-table@6446

@tanstack/table-core

npm i https://pkg.pr.new/TanStack/table/@tanstack/table-core@6446

@tanstack/table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/table-devtools@6446

@tanstack/vue-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/vue-table@6446

@tanstack/vue-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/vue-table-devtools@6446

commit: a0057d3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants