Skip to content

perf: use stable-hash for hashing keys#11073

Draft
43081j wants to merge 1 commit into
TanStack:mainfrom
43081j:jg/stable-hash
Draft

perf: use stable-hash for hashing keys#11073
43081j wants to merge 1 commit into
TanStack:mainfrom
43081j:jg/stable-hash

Conversation

@43081j

@43081j 43081j commented Jul 17, 2026

Copy link
Copy Markdown

Using JSON.stringify is much slower when we only need it to create a stable value hash. Instead, we can use stable-hash.

This is added as a devDependency so it ends up in the bundle rather than being a production dependency.

On my machine, some bench results:

Task name Latency avg (ns) Latency med (ns) Throughput avg (ops/s) Throughput med (ops/s) Samples
'hashKey dev' '29.05 ± 0.10%' '41.00 ± 1.00' '27211238 ± 0.01%' '24390244 ± 580720' 17211565
'hashKey prod' '942.42 ± 3.32%' '916.00 ± 1.00' '1096146 ± 0.01%' '1091703 ± 1191' 530549

✅ 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).

Using `JSON.stringify` is much slower when we only need it to create a
stable value hash. Instead, we can use `stable-hash`.

This is added as a devDependency so it ends up in the bundle rather than
being a production dependency.

On my machine, some bench results:

| Task name | Latency avg (ns) | Latency med (ns) | Throughput avg (ops/s) | Throughput med (ops/s) | Samples |
| -- | -- | -- | -- | -- | -- |
| 'hashKey dev' | '29.05 ± 0.10%' | '41.00 ± 1.00' | '27211238 ± 0.01%' | '24390244 ± 580720' | 17211565 |
| 'hashKey prod' | '942.42 ± 3.32%' | '916.00 ± 1.00' | '1096146 ± 0.01%' | '1091703 ± 1191' | 530549 |
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f5198552-6319-469f-846f-97062bad846c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ 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.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedstable-hash@​0.0.61001009380100

View full report

expect(observer.getCurrentResult()).toMatchObject({
status: 'error',
error: new Error(`Missing queryFn: '${query.queryHash}'`),
error: new Error(`Missing queryFn: '${JSON.stringify(key)}'`),

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.

Shouldn't describeKey be used here?

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