Replace JSON.stringify based hashing by structural hashing#491
Replace JSON.stringify based hashing by structural hashing#491
Conversation
🦋 Changeset detectedLatest commit: 5e2acee The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: 0 B Total Size: 65 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 1.18 kB ℹ️ View Unchanged
|
|
@samwillis I would be keen to micro benchmark this PR against the base one to see how this new hashing function performs. |
5c16993 to
1afdf00
Compare
a0e394e to
49c0166
Compare
|
We benchmarked initial load time for ts/db queries with the old hashing version and this structural hashing version. The performance figures looked similar with no noticeable differences. So we will merge this structural hashing implementation as it doesn't construct (big) intermediate strings and hence is more memory efficient. |
49c0166 to
5e2acee
Compare
This PR changes how we hash values. We used to
JSON.stringifythe values and then hash them. Now, we walk over the value's structure and hash each part. This implementation adapts the implementation from the composites polyfill. The composites hashing only supports hashing composites, we adapted it too also handle arrays, maps, and sets. We also supportBuffer,Uint8Array, andFilebut hash them based on their object reference rather than their value because their value is likely to be big and hence hashing it would be too costly.