Repository navigation
perf: add a plain object and array fast path to deepCompare - #12999
sarankumar1325 wants to merge 3 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code Review by Qodo
1.
|
commit: |
…-plain-values Signed-off-by: sarankumar1325 <[email protected]>
Description of change
OrmUtils.deepCompareruns on everysave()for eachjson/jsonband array column. For plain JSON values it pays for checks that only matter for other kinds of value:isUint8Array, theinstanceofchain,isPrototypeOf, twofor...inpasses, and a chain push/pop for every nested property.This adds a fast path to
compare2Objectsfor the common case. It applies when both values are plain objects (prototypeObject.prototype) or plain arrays (prototypeArray.prototype) with the same prototype:equals()check, so values that defineequalsbehave as before.constructor/prototypechecks and the ancestor-chain cycle check.Object.keyswith a key-count check and apropertyIsEnumerablelookup on the other side, so the two sides must have the same set of enumerable own keys.typeof+!==, and nested objects recurse throughcompare2Objects. SoDate,Buffer/Uint8Array,Map,Setand objects withequals()inside a JSON value still use the existing logic.Everything else (class instances,
Map,Set,Date, typed arrays, null-prototype objects) still goes through the existing path unchanged.Results (the benchmark from the issue, Node 24.22, median, old vs new compiled
OrmUtils):Verification
masterimplementation.deepCompare. The pairs were nested objects/arrays mixingNaN,-0,null/undefined,Date,Buffer,Uint8Array,Map,Set, sparse arrays andconstructor/prototypekeys. Old and new gave 0 different results.tsc --noEmitand eslint report no new errors.One semantic note: the old
for...inloops would also pick up enumerable properties added toObject.prototype/Array.prototype(prototype pollution). The fast path only looks at own keys. It also no longer throws when a JSON object has its ownhasOwnPropertykey.AI disclosure: I wrote this change with help from an AI coding assistant. I reviewed it, ran the tests and benchmarks above, and checked the results myself.
Pull-Request Checklist
masterbranchFixes perf:
OrmUtils.deepCompareis 9-14x slower than necessary forjsoncolumns and array columns on save #12995tests/**.test.ts)docs/docs/**.md) N/A, internal performance change