How can V8 deserialization produce identical results from two distinct hexadecimal strings?

I’m running into a weird issue with V8’s deserialize function. When I take two different hex strings and deserialize them, I get objects that look exactly the same even though the input strings are clearly different.

const v8 = require('v8')

let firstHex = 'ab1c4d330954637265616d5a2000509a2bd7c8ef856242520000000000220b696e697469616c697a656442792206636c69656e74220870726f70657274796f220d636f6d70657469746f72736f222a4b36584e702d4a5a64357163482d38636f694356507168677072446172356666727752746871746c4933505949223d6f2204626c636b4e000000000000304022086465706f73697473542000889a1bafd3a5030000000000000022057469746c65220e4e657720436f6d706574697464722208636f6e74726f6c2208627563686c633561397a6673376537656e3270376a6164396b71757774767870637a6e6e65'
let firstObj = v8.deserialize(Buffer.from(firstHex, 'hex'))
console.dir(firstObj, {depth: null})

let secondHex = 'ab1c4d330954637265616d5a2000509a2bd7c8ef856242520000000000220b696e697469616c697a656442792206636c69656e74220870726f70657274796f220d636f6d706574697864726f732206225a4b36584e702d4a5a64357163482d38636f694356507168677072446172356666727752746871746c4933505949223d6f2204626c636b520822086465706f73697473542000889a1bafd3a5030000000000000022057469746c65220e4e657720436f6d706574697454722208636f6e74726f6c2208627563686c633561397a6673376537656e3270376a6164396b71757774767870637a6e6e65'
let secondObj = v8.deserialize(Buffer.from(secondHex, 'hex'))
console.dir(secondObj, {depth: null})

The hex strings are definitely not the same but when I log both objects they appear identical. What could cause this behavior in V8 deserialization?

Looking at your hex strings, the differences are likely in specific byte sequences that represent V8’s internal metadata or version info - not your actual object content. V8’s binary format includes headers and control bytes that can change between sessions without affecting the object structure. I’ve seen this with cached serialized data where timestamps or session IDs get embedded in the byte stream. Your core object data stays the same, which is why the deserialized objects are identical. Try comparing the hex strings byte-by-byte to see exactly where they differ - it’s usually just a few header bytes that don’t affect the actual content.

This happens because V8’s serialization uses object references and shared string tables for optimization. When you serialize similar objects, V8 creates internal references pointing to the same memory locations during deserialization - even if the hex looks different. I’ve encountered this issue before with cached data structures. V8’s deserialize function resolves different byte sequences to the same object representations due to string interning and object deduplication. Try using JSON.stringify on both deserialized objects and compare the output; you might notice subtle differences that don’t appear with console.dir. The hex differences could also reside in metadata sections rather than the actual object data, which could explain why the final objects appear identical despite differing serialized forms.

Interesting case - V8 serialization’s weird like that. Those hex differences are probably padding bytes or internal pointers that don’t affect the actual object structure. V8 adds extra metadata for garbage collection tracking, but the deserializer just ignores it when rebuilding objects. Try running this on different Node versions - the serialization format changes between versions but usually produces the same results.