Starcounter-Jack / JSON-Patch

Lean and mean Javascript implementation of the JSON-Patch standard (RFC 6902). Update JSON documents using delta patches.
MIT License
1.81k stars 215 forks source link

Ability to generate test operations for original values in the first object (continuation) #228

Closed warpech closed 5 years ago

warpech commented 5 years ago

Continuation of https://github.com/Starcounter-Jack/JSON-Patch/pull/226

Changes that I made compared to the original PR:

Pending questions:

  1. https://github.com/immerjs/immer also registers inverse patches, but they do it in a separate patch, not within the same patch. Is the solution in this PR more or less useful?

Benchmark results:

Before this PR (bbd3002ac0ec296b8289590bdb5fd576dca17e0b, npm run build && npm run bench-duplex)

add operation
 Ops/sec: 3021278 ±0.33% Ran 154893 times in 0.051 seconds.
remove operation
 Ops/sec: 2467208 ±0.45% Ran 127226 times in 0.052 seconds.
replace operation
 Ops/sec: 2854277 ±0.28% Ran 146362 times in 0.051 seconds.
move operation
 Ops/sec: 271583 ±0.37% Ran 15241 times in 0.056 seconds.
copy operation
 Ops/sec: 214417 ±0.45% Ran 18773 times in 0.088 seconds.
test operation
 Ops/sec: 1316006 ±0.31% Ran 67352 times in 0.051 seconds.
===================
generate operation
 Ops/sec: 1680155 ±0.32% Ran 87099 times in 0.052 seconds.
generate operation and re-apply
 Ops/sec: 1483583 ±0.20% Ran 76006 times in 0.051 seconds.
compare operation
 Ops/sec: 427630 ±0.36% Ran 22101 times in 0.052 seconds.
compare operation same but deep objects
 Ops/sec: 122387928 ±0.31% Ran 6230468 times in 0.051 seconds.

After this PR

add operation
 Ops/sec: 3033581 ±0.26% Ran 155154 times in 0.051 seconds.
remove operation
 Ops/sec: 2513818 ±0.33% Ran 129460 times in 0.051 seconds.
replace operation
 Ops/sec: 2804656 ±0.31% Ran 144192 times in 0.051 seconds.
move operation
 Ops/sec: 271968 ±0.38% Ran 15132 times in 0.056 seconds.
copy operation
 Ops/sec: 215846 ±0.35% Ran 19086 times in 0.088 seconds.
test operation
 Ops/sec: 1311638 ±0.33% Ran 67526 times in 0.051 seconds.
==================
generate operation
 Ops/sec: 1705131 ±0.32% Ran 87963 times in 0.052 seconds.
generate operation and re-apply
 Ops/sec: 1452317 ±1.99% Ran 75998 times in 0.052 seconds.
compare operation
 Ops/sec: 422706 ±0.52% Ran 21843 times in 0.052 seconds.
compare operation same but deep objects
 Ops/sec: 115692461 ±0.71% Ran 6021898 times in 0.052 seconds.
================== new benchmarks start here: ==================
generate operation, invertible = true
 Ops/sec: 1607667 ±0.27% Ran 82412 times in 0.051 seconds.
generate operation and re-apply, invertible = true
 Ops/sec: 1401189 ±0.42% Ran 73320 times in 0.052 seconds.
compare operation, invertible = true
 Ops/sec: 237997 ±0.27% Ran 12237 times in 0.051 seconds.
compare operation same but deep objects, invertible = true
 Ops/sec: 116096872 ±0.50% Ran 5978518 times in 0.051 seconds.
warpech commented 5 years ago

cc @pytlesk4

warpech commented 5 years ago

@tomalec please re-review.

I have achieved performing the same test using invertible set as true and then false by creating a new helper functions: variantIt, insertIf and usage of spread operator. I think this is quite neat, similar to NUnit fixtures. I wonder if this is readable, though. Please let me know.

tomalec commented 5 years ago

I wonder if this is readable, though. Please let me know.

At least to me it is :)

pytlesk4 commented 5 years ago

@warpech thanks for taking this over the finish line!

tomalec commented 5 years ago

@pytlesk4 once again thanks for starting a great PR and sorry for being picky :)

warpech commented 5 years ago

Released today as 2.2.0

pytlesk4 commented 5 years ago

@warpech can this get published to NPM?

warpech commented 5 years ago

Done, thanks for pinging me!