The fastest object diff library in JavaScript

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • microdiff

    A fast, zero dependency object and array comparison library. Significantly faster than most other deep comparison libraries and has full TypeScript support.

  • Fast diffing of objects may be seen as rarely needed to a regular user, but it’s very important part of handling vdom/vnode diffs. Recently I researched few lesser web ui libraries for my own use and found out that many of them do not diff vnodes correctly, e.g. in case of RegExp or Date arguments. I don’t remember exact library names vs flaws, but my conclusion was that almost all of non-actively supported libs had it in one way or another. If you want to explore, check that first.

    Seems that this particular library is aware of these potential issues (which motivated me to write this comment): https://github.com/AsyncBanana/microdiff/issues/2

  • jsondiffpatch

    Diff & patch JavaScript objects

  • Hey this is really cool! Not sure how this compares to https://github.com/benjamine/jsondiffpatch which has been unmaintained for some time. But if this could replace it I'd happy to start using it.

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • graphql-live-query

    Realtime GraphQL Live Queries with JavaScript

  • Please compare with modern competitor: json-patch-plus https://github.com/n1ru4l/graphql-live-query/blob/main/packa...

  • symmetry

    Sync objects by diffing and patching (by Two-Screen)

  • I maintain symmetry[1] and wanted to try the benchmark against it, but the results are very inconsistent. Symmetry is anywhere between 50% slower to 20% _faster_ than microdiff on the small object benchmark.

    Symmetry doesn't get a lot of activity, but I've been using it in production for many years. It does some more work on array diffing, which this benchmark doesn't cover, by implementing part of Myers' algorithm.

    [1]: https://github.com/Two-Screen/symmetry/

  • noclip.website

    A digital museum of video game levels

  • I have absolutely written a diffing algorithm like this faster much than it would take to find an appropriate version on npm.

    Every so often I try to reach for an npm library, only to find out that it's suboptimal, doesn't handle my edge cases, or just plain worse than the code I would have written.

    The last time I tried to do this, I wanted a hash map with custom equality functions on the keys, since JS doesn't have one built-in by default. I searched for about 2 hours and didn't find a single one that actually worked (several claimed to be, but actually didn't work...)

    So I wrote my own in about 100 lines. [0]

    Data structures and algorithms tend to be really awful on npm.

    [0] https://github.com/magcius/noclip.website/blob/master/src/Ha...

  • js-diff-benchmarks

    Benchmarks of JS object diffing libraries.

  • Here is the microdiff benchmark wrapped in benchmark.js: https://github.com/stephank/js-diff-benchmarks

    I added three more libraries, and also the size in bytes of `JSON.stringify(result)` for each. (That was also important for me in making symmetry.)

    The results from benchmark.js are a lot more consistent on my laptop:

    ```

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts