Skip to content

fix: aggregation performance#6425

Merged
KevinVandy merged 1 commit into
betafrom
fix-aggregation-perf
Jul 16, 2026
Merged

fix: aggregation performance#6425
KevinVandy merged 1 commit into
betafrom
fix-aggregation-perf

Conversation

@KevinVandy

@KevinVandy KevinVandy commented Jul 16, 2026

Copy link
Copy Markdown
Member

🎯 Changes

✅ 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 performance for grouped tables and row aggregation, especially with single- and multi-level grouping.
    • Reduced unnecessary memory usage during aggregation.
    • Improved handling of date and numeric values in minimum, maximum, and range calculations.
  • Bug Fixes

    • Improved correctness of aggregated values when grouped rows contain duplicate or nested data.
  • Documentation

    • Added a performance analysis and benchmarking guide for grouping and aggregation.

@nx-cloud

nx-cloud Bot commented Jul 16, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 6674336

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

☁️ Nx Cloud last updated this comment at 2026-07-16 14:08:04 UTC

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Grouped row construction and aggregation are optimized through unique-row normalization, cached grouping values, single-pass range aggregators, and lazy aggregation caches. Benchmark documentation and the bundle-size limit are also updated.

Changes

Grouped aggregation performance

Layer / File(s) Summary
Grouped row normalization and grouping
packages/table-core/src/features/row-aggregation/rowAggregationFeature.utils.ts, packages/table-core/src/features/column-grouping/createGroupedRowModel.ts
Adds unique-row normalization and routes grouped aggregation through cached grouping values and unique aggregation inputs.
Aggregation functions and lazy caches
packages/table-core/src/features/row-aggregation/aggregationFns.ts, packages/table-core/src/features/row-aggregation/rowAggregationFeature.ts, packages/table-core/src/features/row-aggregation/rowAggregationFeature.types.ts
Rewrites range aggregators as single-pass scans and changes row aggregation caches to lazy initialization for grouped rows.
Performance documentation and bundle limit
perf-agg.md, package.json
Documents benchmark results, implementation changes, and remaining optimization gaps; increases the table-core bundle limit from 20 KB to 25 KB.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • TanStack/table#6376: Modifies grouped-row population behavior in the same createGroupedRowModel.ts code path.
🚥 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 matches the main change: improving aggregation performance.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-aggregation-perf

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.

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026

Copy link
Copy Markdown
More templates

@tanstack/alpine-table

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

@tanstack/angular-table

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

@tanstack/angular-table-devtools

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

@tanstack/ember-table

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

@tanstack/lit-table

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

@tanstack/match-sorter-utils

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

@tanstack/preact-table

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

@tanstack/preact-table-devtools

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

@tanstack/react-table

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

@tanstack/react-table-devtools

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

@tanstack/solid-table

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

@tanstack/solid-table-devtools

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

@tanstack/svelte-table

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

@tanstack/table-core

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

@tanstack/table-devtools

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

@tanstack/vue-table

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

@tanstack/vue-table-devtools

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

commit: 6674336

@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: 2

🤖 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 `@package.json`:
- Line 61: Revert the package size limit from 25 KB to 20 KB so the configured
constraint matches the documented bundle size and enforces the existing strict
threshold.

In `@packages/table-core/src/features/column-grouping/createGroupedRowModel.ts`:
- Around line 231-246: Update the grouping value logic around
_groupingValuesCache so that when getGroupingValue exists but the cache is
absent, it still computes groupingValue by calling getGroupingValue with
row.original, row.index, and row. Preserve the existing cached-value lookup and
cache-population paths.
🪄 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: dc33888f-8dfc-46a6-b33c-f9c892857b08

📥 Commits

Reviewing files that changed from the base of the PR and between 6acc1e9 and 6674336.

📒 Files selected for processing (7)
  • package.json
  • packages/table-core/src/features/column-grouping/createGroupedRowModel.ts
  • packages/table-core/src/features/row-aggregation/aggregationFns.ts
  • packages/table-core/src/features/row-aggregation/rowAggregationFeature.ts
  • packages/table-core/src/features/row-aggregation/rowAggregationFeature.types.ts
  • packages/table-core/src/features/row-aggregation/rowAggregationFeature.utils.ts
  • perf-agg.md

Comment thread package.json
Comment on lines +231 to +246
if (getGroupingValue) {
const cache = (row as any)._groupingValuesCache as
| Record<string, unknown>
| undefined
if (cache && hasOwn(cache, columnId)) {
groupingValue = cache[columnId]
} else if (cache) {
groupingValue = cache[columnId] = getGroupingValue(
row.original,
row.index,
row,
)
}
} else {
groupingValue = row.getValue(columnId)
}

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Provide a fallback when _groupingValuesCache is undefined.

If cache evaluates to falsy, groupingValue is never assigned and remains undefined. Even though the cache might currently be eagerly initialized (as noted in perf-agg.md), relying on this behavior makes the code brittle against future refactoring (such as lazy initialization). Add an else block to compute the grouping value when the cache is absent.

🐛 Proposed fix
     if (getGroupingValue) {
       const cache = (row as any)._groupingValuesCache as
         | Record<string, unknown>
         | undefined
       if (cache && hasOwn(cache, columnId)) {
         groupingValue = cache[columnId]
-      } else if (cache) {
-        groupingValue = cache[columnId] = getGroupingValue(
+      } else {
+        groupingValue = getGroupingValue(
           row.original,
           row.index,
           row,
         )
+        if (cache) {
+          cache[columnId] = groupingValue
+        }
       }
     } else {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (getGroupingValue) {
const cache = (row as any)._groupingValuesCache as
| Record<string, unknown>
| undefined
if (cache && hasOwn(cache, columnId)) {
groupingValue = cache[columnId]
} else if (cache) {
groupingValue = cache[columnId] = getGroupingValue(
row.original,
row.index,
row,
)
}
} else {
groupingValue = row.getValue(columnId)
}
if (getGroupingValue) {
const cache = (row as any)._groupingValuesCache as
| Record<string, unknown>
| undefined
if (cache && hasOwn(cache, columnId)) {
groupingValue = cache[columnId]
} else {
groupingValue = getGroupingValue(
row.original,
row.index,
row,
)
if (cache) {
cache[columnId] = groupingValue
}
}
} else {
groupingValue = row.getValue(columnId)
}
🤖 Prompt for 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.

In `@packages/table-core/src/features/column-grouping/createGroupedRowModel.ts`
around lines 231 - 246, Update the grouping value logic around
_groupingValuesCache so that when getGroupingValue exists but the cache is
absent, it still computes groupingValue by calling getGroupingValue with
row.original, row.index, and row. Preserve the existing cached-value lookup and
cache-population paths.

@KevinVandy KevinVandy merged commit 5d57b46 into beta Jul 16, 2026
10 checks passed
@KevinVandy KevinVandy deleted the fix-aggregation-perf branch July 16, 2026 14:49
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.

1 participant