feat(preferred): add object-identity as an object-hash replacement#749
Closed
maraisr wants to merge 4 commits into
Closed
feat(preferred): add object-identity as an object-hash replacement#749maraisr wants to merge 4 commits into
maraisr wants to merge 4 commits into
Conversation
Add object-identity alongside safe-stable-stringify in the serializer suggestions, as well as switch examples to it.
92645d0 to
30f3b92
Compare
gameroman
reviewed
Jun 24, 2026
List object-identity as a documented replacement option for object-hash.
ca13f41 to
aa9d12e
Compare
dreyfus92
reviewed
Jun 25, 2026
Collaborator
There was a problem hiding this comment.
hey @maraisr thanks for this, and for the honest write-up of the trade-offs & the disclosure are appreciated.
happy to take it as a documented option, but a few changes first:
- revert the safe-stable-stringify swaps in the web crypto + bun examples. the pr says it "stays alongside" but the diff removes it; let's leave those examples on safe-stable-stringify and let object-identity stand on its own section.
- order it after ohash in the object-hash
replacementsarray. this isn't cosmetic: the cli picks the first compatible entry, so prepending it makesobject-identitythe surfaced recommendation over ohash, and replacements.fyi renders the array in order so it'd also be top-listed there. given ohash is the maintained successor at ~1000x the adoption, it should lead.
worth flagging for transparency that object-identity is ~6.5k/week vs our ~10k soft bar, so i'm taking it as documented-but-not-leading rather than promoting it ahead of ohash.
also i'd love @43081j's input before merging this one.
Author
|
Thank you for your review here @dreyfus92, and do apologise for any inconvenience this may have caused you. Maybe another time! |
Contributor
|
Very happy to add this once you see some adoption 👍 Please do recreate this PR then as it would be nice to include it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
There isn't a dedicated open issue for this one, it builds on the existing
object-hashreplacement page (prior context in #245). Happy to open a tracking issue first if you'd rather discuss it there.📚 Description
This PR suggests
object-identityas another replacement option forobject-hash.object-identityto theobject-hashmapping inpreferred.json(as adocumentedreplacement, alongsideohash), andFull disclosure: I'm the author of
object-identity, so please take this as you will. I've tried to keep every claim backed by numbers and to be honest about the trade-offs, very happy to adjust or drop anything.Why it fits here
object-identitycanonicalizes any value into a stable identity string, exactly the lib you reach for when you need a deterministic key to hash or to compare. It's deep and cycle-safe by default, and it's tiny.Smaller — both are zero-dependency; minified + gzipped:
object-identitysafe-stable-stringifyThat's roughly 4.5× smaller.
Faster — I am using my benchmarks for these two libraries (ops/sec, higher is better):
object-identitysafe-stable-stringifySo it's ahead on most cases (≈1.3×–2.1×) and about line-ball on the wide "big" object, where
safe-stable-stringifyis marginally quicker (room for improvement).Trade-offs / what it doesn't do
object-identityis deliberately opinionated: it always produces a canonical, cycle-safe identity and exposes no options, so it doesn't cover some ofsafe-stable-stringify's options, for example:deterministicmaximumDepth/maximumBreadthlimitsreplacer, indentation / pretty-printing, and BigInt handlingIt also emits an internal identity string rather than valid, human-readable JSON. In practice, for what this utility is usually used for, is for deriving a stable key to feed a hash, or checking structural equality. None of those tend to matter; you just want the same input to map to the same output. If you specifically need canonical JSON out, a
replacer, or pretty output,safe-stable-stringifyremains the better tool, which is why it stays alongside.Very open to feedback, and happy to reword, or keep this docs-only and drop the manifest entry if that sits better with how you'd like to position it. Thanks for considering it, and for maintaining this ❤️