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

Performance Degradation Starting In v5.2.0 #159

Closed
SyntaxNode opened this issue Feb 9, 2022 · 2 comments · Fixed by #197
Closed

Performance Degradation Starting In v5.2.0 #159

SyntaxNode opened this issue Feb 9, 2022 · 2 comments · Fixed by #197

Comments

@SyntaxNode
Copy link

SyntaxNode commented Feb 9, 2022

Greetings From https://github.com/prebid/prebid-server

We use json-patch in our project and observed a performance difference when we upgraded to v5 from an older version. This is a high scale application which is particularly sensitive to memory allocations. I turned the MergePatch example in the readme to a benchmark test and found the following results on the 5.2.0 and 5.1.0 version branches with Go 1.16:

func BenchmarkMergePatch(b *testing.B) {
	original := []byte(`{"name": "John", "age": 24, "height": 3.21}`)
	target := []byte(`{"name": "Jane", "age": 24}`)
	alternative := []byte(`{"name": "Tina", "age": 28, "height": 3.75}`)

	patch, err := CreateMergePatch(original, target)
	if err != nil {
		panic(err)
	}

	for n := 0; n < b.N; n++ {
		MergePatch(alternative, patch)
	}
}
v5.2.0  BenchmarkMergePatch-12    	   85310	     14823 ns/op	    6454 B/op	     154 allocs/op
v5.1.0  BenchmarkMergePatch-12    	  216194	      6405 ns/op	    2634 B/op	      56 allocs/op

v5.2.0+ is using significantly more memory in terms of bytes and allocations. I am curious if this is a known change or perhaps we need to modify our calls to optimize for lower memory usage?

Thank you.

@SyntaxNode SyntaxNode changed the title Performance Degradation v4 to v5 Performance Degradation Starting In v5.2.0 Feb 10, 2022
@evanphx
Copy link
Owner

evanphx commented Jan 12, 2024

Sorry for the long delay, I'm looking into this. Part of the reason is some correctness fixes.

@SyntaxNode
Copy link
Author

No worries. Thank you for the fix.

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 a pull request may close this issue.

2 participants