feat: improve sortFns, filterFns, aggregationFns performance more#6371
Conversation
|
View your CI Pipeline Execution ↗ for commit 9df72cc
☁️ Nx Cloud last updated this comment at |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds email columns and faker-generated email values across the sorting examples, and refactors table-core sorting, filtering, aggregation, and sort functions with matching tests and perf catalog updates. ChangesSorting Examples: Email Column
Table-Core Performance Refactors
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (3)
examples/lit/sorting/src/makeData.ts (1)
25-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueEmail is generated from
lastNameeven when the row'slastNameis set toundefined.Since
lastNamevariable directly (line 32) regardless of the coin-flip that nulls out the returnedlastNamefield (line 30), rows with an undefined last name will still show a last-name-derived email. This is a demo data quirk, not a functional bug, but slightly inconsistent for anyone inspecting the data.🤖 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 `@examples/lit/sorting/src/makeData.ts` around lines 25 - 34, The generated email in makeData currently uses the local lastName value even when the returned object omits lastName, so the demo data can look inconsistent. Update makeData so the email is derived from the same effective lastName that is returned in the object, or fall back to a non-last-name-based value when lastName is undefined; keep the logic localized around makeData and its email construction.perf-done.md (1)
1601-1666: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDoc claims "Risk: None" but misses an edge case found in review.
The catalog entry states this rewrite is a "pure strength reduction" with semantics "preserved verbatim," but the reviewed source (
filterFns.ts:224-242,259-277) has a latent bug whereNumber('')coerces to0rather thanNaN, causing blank-min + negative-max combinations to bypass the max bound. Worth updating this note once the source fix lands.🤖 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 `@perf-done.md` around lines 1601 - 1666, Update the `filterFn_between` / `filterFn_betweenInclusive` performance note in `perf-done.md` to remove the blanket “Risk: None” / “semantics preserved verbatim” claim and add the reviewed edge case about `Number('')` coercing to `0`, which can let blank-min plus negative-max cases bypass the max bound. Keep the entry aligned with the actual `filterFns.ts` behavior and mention that the note should be revised once the source fix for `filterFn_between` and `filterFn_betweenInclusive` is in place.packages/table-core/tests/unit/fns/filterFns.test.ts (1)
570-626: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winConsider adding a blank-min + negative-max case.
These new
between/betweenInclusivetests cover strict/inclusive/open-ended/reversed cases well, but none pair a blank endpoint (''/undefined) with a negative number on the other side — the exact combination that trips theNumber('') === 0issue flagged infilterFns.ts. Adding such a case would have caught that regression.🤖 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/tests/unit/fns/filterFns.test.ts` around lines 570 - 626, Add a regression test for filterFns.between and/or filterFns.betweenInclusive that uses a blank endpoint ('' or undefined) paired with a negative bound, since the current cases in filterFns.test only cover positive values. Update the describe blocks for filterFns.between and filterFns.betweenInclusive to include this blank-min/negative-max scenario and assert the expected open-ended behavior so the Number('') coercion issue is caught.
🤖 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/features/row-sorting/createSortedRowModel.ts`:
- Around line 104-106: The comparator in createSortedRowModel should treat the
“both undefined” case as a tie before applying sortUndefined handling. Update
the undefined-check branch so that when both aUndefined and bUndefined are true
it returns 0 and allows later multi-sort keys to resolve the order, while
keeping the existing first/last behavior only for the single-undefined case. Use
the aUndefined, bUndefined, and sortUndefined logic in the sorting comparator to
locate the fix.
In `@packages/table-core/src/fns/filterFns.ts`:
- Around line 224-242: The upper-bound check in the range filter logic is
incorrectly treating a blank minimum as numeric zero, which lets rows pass when
max is negative. Update the range validation in filterFns.ts within the function
handling the min/max comparison so blank endpoints are excluded before computing
numericMin/numericMax or doing the reversed-range check. Apply the same fix in
filterFn_betweenInclusive so both range filters consistently ignore empty bounds
and still enforce the upper limit.
- Around line 359-365: The arrIncludes filter path in filterFns.ts can throw
when row values are nullish, so update filterFn_arrIncludes to guard the row
value before calling includes. Reuse the same null/Array.isArray-style check
already used by the sibling helpers in this module, and keep the behavior
aligned with column_getAutoFilterFn’s arrIncludes selection for array columns.
In `@packages/table-core/tests/unit/core/table/rowModelSlots.test.ts`:
- Around line 164-166: The sort assertion in rowModelSlots.test.ts should
reflect the tie-break behavior for rows with undefined priority. Update the
expectation for table.getSortedRowModel().rows.map(...) so the rows with tied
primary sort key use the secondary inverted score ordering, with the relevant
check around the table sorting setup and row.original.name results.
---
Nitpick comments:
In `@examples/lit/sorting/src/makeData.ts`:
- Around line 25-34: The generated email in makeData currently uses the local
lastName value even when the returned object omits lastName, so the demo data
can look inconsistent. Update makeData so the email is derived from the same
effective lastName that is returned in the object, or fall back to a
non-last-name-based value when lastName is undefined; keep the logic localized
around makeData and its email construction.
In `@packages/table-core/tests/unit/fns/filterFns.test.ts`:
- Around line 570-626: Add a regression test for filterFns.between and/or
filterFns.betweenInclusive that uses a blank endpoint ('' or undefined) paired
with a negative bound, since the current cases in filterFns.test only cover
positive values. Update the describe blocks for filterFns.between and
filterFns.betweenInclusive to include this blank-min/negative-max scenario and
assert the expected open-ended behavior so the Number('') coercion issue is
caught.
In `@perf-done.md`:
- Around line 1601-1666: Update the `filterFn_between` /
`filterFn_betweenInclusive` performance note in `perf-done.md` to remove the
blanket “Risk: None” / “semantics preserved verbatim” claim and add the reviewed
edge case about `Number('')` coercing to `0`, which can let blank-min plus
negative-max cases bypass the max bound. Keep the entry aligned with the actual
`filterFns.ts` behavior and mention that the note should be revised once the
source fix for `filterFn_between` and `filterFn_betweenInclusive` is in place.
🪄 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: 93ea5b37-a160-4a3b-b340-1e35aa42e786
📒 Files selected for processing (31)
examples/alpine/sorting/src/main.tsexamples/alpine/sorting/src/makeData.tsexamples/angular/sorting/src/app/app.tsexamples/angular/sorting/src/app/makeData.tsexamples/lit/sorting/src/main.tsexamples/lit/sorting/src/makeData.tsexamples/preact/sorting/src/main.tsxexamples/preact/sorting/src/makeData.tsexamples/react/sorting/src/main.tsxexamples/react/sorting/src/makeData.tsexamples/solid/sorting/src/App.tsxexamples/solid/sorting/src/makeData.tsexamples/svelte/sorting/src/App.svelteexamples/svelte/sorting/src/makeData.tsexamples/vanilla/sorting/src/main.tsexamples/vanilla/sorting/src/makeData.tsexamples/vue/sorting/src/App.vueexamples/vue/sorting/src/makeData.tspackages/table-core/src/features/column-filtering/columnFilteringFeature.utils.tspackages/table-core/src/features/row-sorting/createSortedRowModel.tspackages/table-core/src/fns/aggregationFns.tspackages/table-core/src/fns/filterFns.tspackages/table-core/src/fns/sortFns.tspackages/table-core/tests/unit/core/table/rowModelSlots.test.tspackages/table-core/tests/unit/features/column-filtering/columnFilteringFeature.utils.test.tspackages/table-core/tests/unit/fns/aggregationFns.test.tspackages/table-core/tests/unit/fns/filterFns.test.tspackages/table-core/tests/unit/fns/sortFns.test.tsperf-done.mdperf-skipped.mdperf-todo.md
🎯 Changes
✅ Checklist
pnpm test:pr.Summary by CodeRabbit
New Features
Bug Fixes