perf: use stable-hash for hashing keys#11073
Conversation
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 |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
| expect(observer.getCurrentResult()).toMatchObject({ | ||
| status: 'error', | ||
| error: new Error(`Missing queryFn: '${query.queryHash}'`), | ||
| error: new Error(`Missing queryFn: '${JSON.stringify(key)}'`), |
There was a problem hiding this comment.
Shouldn't describeKey be used here?
Using
JSON.stringifyis much slower when we only need it to create a stable value hash. Instead, we can usestable-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:
✅ Checklist
pnpm run test:pr.🚀 Release Impact