use-async-resource icon indicating copy to clipboard operation
use-async-resource copied to clipboard

replace object-hash with JSON.stringify

Open gajus opened this issue 4 years ago • 4 comments

There is no obvious reason for using object-hash here and it adds 32kb to the bundle size.

https://bundlephobia.com/[email protected]

gajus avatar Mar 25 '21 06:03 gajus

Agreed, object-hash is large enough, but JSON.stringify doesn't preserve object equivalence: for identical objects with different order of their keys, it results in different values.

Another thing to keep note of: very large objects will result in very large keys, whereas a hash function will have the same length regardless of the object sizes.

There are alternatives, smaller and (maybe) faster. Too many actually. But I have not done much research:

  • https://www.npmjs.com/package/fast-json-stable-stringify
  • https://www.npmjs.com/package/json-stable-stringify
  • https://www.npmjs.com/package/fast-stable-stringify
  • https://www.npmjs.com/package/faster-stable-stringify

But again, they are stringifiers, not hashers.

andreiduca avatar Mar 25 '21 16:03 andreiduca

also scope hoist in parcel (not sure about webpack) doesn't work because of object-hash

miguelski avatar Apr 28 '21 16:04 miguelski

I will look into alternatives. Thank you for bringing it up. 🙏🏻

andreiduca avatar May 08 '21 16:05 andreiduca

Any chance of this getting addressed? It is currently being flagged as the biggest dead weight in our app.

gajus avatar Jul 23 '22 12:07 gajus