Closed warpech closed 5 years ago
Clever idea, however our current usage in Palindrom would require to parse the stringified JSON for sanity-checking: https://github.com/Palindrom/Palindrom/blob/e7442d6946cce9afb4b7e8c270b84287d110af96/src/palindrom.js#L211
However, a way to fix that: provide a validation function from Palindrom to JSONPatcherProxy, so that JSONPatcherProxy can validate the patch before generating it.
There is also some (~30%) pentalty in calling JSON.serialize
separately for each operaion, as opposed to calling it once for the patch array (as we do now): http://jsbench.github.io/#2cd4ee42cc5997ddd05b7f348ab218d0
We discussed today with @tomalec and @eriksunsol, that this change is not worth the performance penalty. Rather than fixing the code in this library, we could write a warning in README.md
that patch immutability is not a feature on this library. If you use the patch asynchrously, you ought to apply immutability on the patch object in your code. In our case, Palindrom libary would apply immutability on the patch before inserting it to the queue.
Closing in favor of https://github.com/Palindrom/JSONPatcherProxy/pull/55
Continuation of https://github.com/Palindrom/JSONPatcherProxy/pull/46 with test and performance improvement.
cc @eriksunsol
There is a serious degradation in performance (see "Complex mutation"), but I think it is an important fix. @tomalec WDYT?
Performance before this PR (
npm run bench
)Performance after this PR (
npm run bench
)