镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Shortcut when two json documents are same - #37

Merged
tamalsaha merged 3 commits into
gomodules:release-2.0from
nak3:fix-bench
Aug 14, 2023
Merged

tamalsaha merged 3 commits into
gomodules:release-2.0from
nak3:fix-bench

Conversation

@nak3

@nak3 nak3 commented Aug 9, 2023 •

Copy link
Copy Markdown

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

CLAassistant commented Aug 9, 2023 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

nak3 added 2 commits August 9, 2023 15:45
Signed-off-by: Kenjiro Nakayama <nakayamakenjiro@gmail.com>
Signed-off-by: Kenjiro Nakayama <nakayamakenjiro@gmail.com>
@nak3

nak3 commented Aug 9, 2023

Copy link
Copy Markdown
Author

/cc @tamalsaha @howardjohn

Could you please take a look?

Comment thread v2/jsonpatch.go Resolved
Signed-off-by: Kenjiro Nakayama <nakayamakenjiro@gmail.com>
@tamalsaha
tamalsaha merged commit 17d7994 into gomodules:release-2.0 Aug 14, 2023
@tamalsaha

tamalsaha commented Aug 14, 2023 •

Copy link
Copy Markdown

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.

3 participants