Skip to content

perf: special case arrays in partialMatchKey#11084

Open
43081j wants to merge 2 commits into
TanStack:mainfrom
43081j:jg/partial-wins
Open

perf: special case arrays in partialMatchKey#11084
43081j wants to merge 2 commits into
TanStack:mainfrom
43081j:jg/partial-wins

Conversation

@43081j

@43081j 43081j commented Jul 19, 2026

Copy link
Copy Markdown

🎯 Changes

This does 2 things:

  1. If the values being compared are both arrays, iterate through them
    directly
  2. Use a for...of instead of allocating an arrow function per
    recursive call

The results:

Task name Latency avg (ns) Latency med (ns) Throughput avg (ops/s) Throughput med (ops/s) Samples
'partialMatchKey dev' '38.21 ± 0.16%' '42.00 ± 0.00' '24035274 ± 0.00%' '23809524 ± 1' 13086480
'partialMatchKey prod' '102.05 ± 0.52%' '84.00 ± 1.00' '10289814 ± 0.02%' '11904762 ± 143431' 4899508

✅ Checklist

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

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes

    • Improved partial key matching for arrays, ensuring comparisons consistently evaluate the expected indices.
    • Preserved matching behavior for non-array objects while improving consistency.
  • Performance

    • Optimized partial key matching to reduce unnecessary processing.
  • Chores

    • Added a patch release note for the improvement.

This does 2 things:

1. If the values being compared are both arrays, iterate through them
   directly
2. Use a `for...of` instead of allocating an arrow function per
   recursive call

The results:

| Task name | Latency avg (ns) | Latency med (ns) | Throughput avg (ops/s) | Throughput med (ops/s) | Samples |
| -- | -- | -- | -- | -- | -- |
| 'partialMatchKey dev' | '38.21 ± 0.16%' | '42.00 ± 0.00' | '24035274 ± 0.00%' | '23809524 ± 1' | 13086480 |
| 'partialMatchKey prod' | '102.05 ± 0.52%' | '84.00 ± 1.00' | '10289814 ± 0.02%' | '11904762 ± 143431' | 4899508 |
@43081j
43081j force-pushed the jg/partial-wins branch from 613bd6b to 117c7cf Compare July 19, 2026 15:37
@coderabbitai

coderabbitai Bot commented Jul 19, 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: 8decf332-857b-4232-bd6e-65c9dd5028c2

📥 Commits

Reviewing files that changed from the base of the PR and between 44f38df and 117c7cf.

📒 Files selected for processing (2)
  • .changeset/humble-tips-try.md
  • packages/query-core/src/utils.ts

📝 Walkthrough

Walkthrough

partialMatchKey now uses explicit array index and object key iteration, with a Changesets patch entry documenting the performance improvement for @tanstack/query-core.

Changes

Partial key matching

Layer / File(s) Summary
Array and object matching
packages/query-core/src/utils.ts, .changeset/humble-tips-try.md
partialMatchKey compares arrays by indexed elements and non-array objects by their keys; a patch changeset records the update.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: special-casing arrays in partialMatchKey for performance.
Description check ✅ Passed The description follows the template and includes changes, checklist items, and release impact with a changeset.
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.

@TkDodo

TkDodo commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

@43081j what’s the “before” results?

@nx-cloud

nx-cloud Bot commented Jul 20, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 1a17713

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 7m 38s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 25s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-20 10:58:27 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jul 20, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@11084

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@11084

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@11084

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@11084

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@11084

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@11084

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@11084

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@11084

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@11084

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@11084

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@11084

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@11084

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@11084

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@11084

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@11084

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@11084

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@11084

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@11084

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@11084

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@11084

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@11084

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@11084

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@11084

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@11084

commit: 1a17713

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