Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcut when two json documents are same #37

Merged
merged 3 commits into from Aug 14, 2023

Conversation

nak3
Copy link

@nak3 nak3 commented Aug 9, 2023

When two json documents are same, patch is not created.
However, current code tries to check the diff and takes some time and memory.
Hence this patch adds bytes.Equal before creating patch to skip it.

Also, the current bench mark largeArray is using a same value
so update it to use different values in array.

Here is the bench mark before(13a9e4a) and after (d5e5602).

  • large_array becomes much faster.
  • reflect.DeepEqual does not make much performance degradation as per complex and simple tests.
goos: linux
goarch: amd64
pkg: gomodules.xyz/jsonpatch/v2
cpu: Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
                          │     before      │                after                 │
                          │     sec/op      │    sec/op     vs base                │
CreatePatch/complex-8          152.5µ ± 22%   150.4µ ±  4%        ~ (p=0.796 n=10)
CreatePatch/large_array-8   1479.550µ ± 26%   8.061µ ± 28%  -99.46% (p=0.000 n=10)
CreatePatch/simple-8           19.30µ ± 25%   14.77µ ± 10%  -23.46% (p=0.023 n=10)
geomean                        163.3µ         26.16µ        -83.98%

                          │    before     │                after                 │
                          │     B/op      │     B/op      vs base                │
CreatePatch/complex-8        83.80Ki ± 0%   83.83Ki ± 0%   +0.04% (p=0.013 n=10)
CreatePatch/large_array-8   945.37Ki ± 0%   36.05Ki ± 0%  -96.19% (p=0.000 n=10)
CreatePatch/simple-8         2.289Ki ± 9%   2.539Ki ± 8%  +10.92% (p=0.005 n=10)
geomean                      56.60Ki        19.72Ki       -65.15%

                          │     before     │                after                │
                          │   allocs/op    │  allocs/op   vs base                │
CreatePatch/complex-8          1.180k ± 0%   1.182k ± 0%   +0.17% (p=0.001 n=10)
CreatePatch/large_array-8   14785.000 ± 0%    4.000 ± 0%  -99.97% (p=0.000 n=10)
CreatePatch/simple-8            33.00 ± 6%    37.00 ± 5%  +12.12% (p=0.001 n=10)
geomean                         831.9         55.93       -93.28%

@CLAassistant
Copy link

CLAassistant commented Aug 9, 2023

CLA assistant check
All committers have signed the CLA.

Signed-off-by: Kenjiro Nakayama <nakayamakenjiro@gmail.com>
Signed-off-by: Kenjiro Nakayama <nakayamakenjiro@gmail.com>
@nak3
Copy link
Author

nak3 commented Aug 9, 2023

/cc @tamalsaha @howardjohn

Could you please take a look?

v2/jsonpatch.go Outdated Show resolved Hide resolved
Signed-off-by: Kenjiro Nakayama <nakayamakenjiro@gmail.com>
@tamalsaha tamalsaha merged commit 17d7994 into gomodules:release-2.0 Aug 14, 2023
3 checks passed
@tamalsaha
Copy link

tamalsaha commented Aug 14, 2023

https://github.com/gomodules/jsonpatch/releases/tag/v2.4.0

Thanks for the contribution @nak3 !

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.

None yet

3 participants