Skip to content

perf: optimize json-diff - #132

Open
jedluhmann wants to merge 14 commits into
andreyvit:masterfrom
jedluhmann:jl-optimize-json-diff
Open

perf: optimize json-diff#132
jedluhmann wants to merge 14 commits into
andreyvit:masterfrom
jedluhmann:jl-optimize-json-diff

Conversation

@jedluhmann

Copy link
Copy Markdown

Optimizations:

lib/index.js

  • lines 21-34: Use JSON.stringify() to bypass diff logic when objects are equal
  • line 101: Cache changes calculated in this.diff() for later use in arrayDiff where op is 'equal'
  • line 101: Switched the order of arguments when calling this.diff() for consistency (candidate is the original value) and to allow caching (reuse change values calculated here in later fuzzy matching)
  • line 110: Break out of loop when exact match (value and position) is found
  • lines: 179-187: Use JSON.stringify() to bypass diff logic when arrays are equal

Fixes:

lib/index.js

  • lines 173-176: Call sort on array arguments, not scalarized sequences

Upgrades include bun, eslint, prettier, mocha, chai, and c8.
…tringify for array equality)

Some comments are left in this commit to help clarify what is being optimized. These comments will be removed in the next commit.

Changes:
- Cache changes calculated in findMatchingObject() for later use in arrayDiff where op is 'equal'
- Use JSON.stringify() to bypass diff logic when arrays are equal
- findMatchingObject: Switched the order of arguments when calling this.diff() for consistency (candidate is the original value) and to allow caching (reuse change values calculated here in later fuzzy matching)
…condition immediately above for truthy values
@jedluhmann jedluhmann changed the title Jl optimize json diff Jl optimize json-diff Sep 1, 2026
@jedluhmann jedluhmann changed the title Jl optimize json-diff Optimize json-diff Sep 1, 2026
@jedluhmann jedluhmann changed the title Optimize json-diff optimize json-diff Sep 1, 2026
@jedluhmann jedluhmann changed the title optimize json-diff perf: optimize json-diff Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant