-
Notifications
You must be signed in to change notification settings - Fork 69
Migrate to encoding/json/v2 #292
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
base: master
Are you sure you want to change the base?
Conversation
For the
|
a4b6871
to
bdce391
Compare
I fixed the test failure. |
/assign @BenTheElder @liggitt |
/assign @jpbetz |
I suspect using a json marshal function (like MarshalWrite) that doesn't append a newline would be a more efficient way to accomplish that |
fieldpath/serialize-pe.go
Outdated
return nil, fmt.Errorf("parsing JSON: %v", err) | ||
} | ||
|
||
k := rawKey.String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is rawKey.String() the same as decoding to a string, in terms of interpreting escape sequences, etc?
{ | ||
JSON: `1.0`, | ||
IntoType: reflect.TypeOf(json.Number("")), | ||
Want: json.Number("1.0"), | ||
}, | ||
{ | ||
JSON: `1`, | ||
IntoType: reflect.TypeOf(json.Number("")), | ||
Want: json.Number("1"), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious if it's ok to drop these... were they added to try to catch a specific issue?
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: inteon The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The The serialize benchmarks still look pretty rough. Need to see what we can improve there. |
did you run the full set of benchmarks to see how we looked across all of them? |
Thanks for the updates, how are the overall benchmarks looking (not just the subset in the description)? As you were adjusting the implementation, were there any unit tests it would make sense to add to catch edges the previous implementations handled we want to ensure the new one does as well? I'm thinking specifically of things like:
|
First off- it's amazing to see this happening and the benchmarks are VERY promising. Thanks @inteon! To get this to the finish line, and merge, what should our criteria be? I chatted offline with @liggitt briefly and some of the criteria we discussed was:
Intuitively, it seems like the deserialization is already sufficiently fast. I suspect we need to optimize serialization a bit further since we serialize managed fields on all updates (not just patches). That said, I'm willing to be data driven here. If we can show downstream scale and performance is acceptable, I'm willing to accept a higher serialization perf regression in order to migrate to json/v2. Thoughts, concerns? |
Signed-off-by: Tim Ramlot <[email protected]>
Signed-off-by: Tim Ramlot <[email protected]>
Signed-off-by: Tim Ramlot <[email protected]>
Signed-off-by: Tim Ramlot <[email protected]>
Signed-off-by: Tim Ramlot <[email protected]>
Signed-off-by: Tim Ramlot <[email protected]>
Signed-off-by: Tim Ramlot <[email protected]>
Signed-off-by: Tim Ramlot <[email protected]>
Update check the new numbers in my PR description, upgrading encoding/json/v2 did improve performance! |
Did some further tuning and got the # allocations lower than on master. |
even with stable json/v2, we might need to temporarily use a fork, otherwise we kubernetes branches that aren't on that go version yet can't update SMD. but we should encapsulate it and plan to eliminate it when we're ready to require that minimum go version even kubernetes master isn't on 1.25 yet |
Am I reading correctly that B/op and allocs/op are ~equivalent or better than master on pretty much all benchmarks? If so, that's amazing progress! Paired with a close review and functional/correctness test coverage to make sure the new approach behaves identically to the old version (especially in terms of what it accepts/rejects/produces in edge cases like leading/trailing/non-normalized/invalid inputs), this looks really promising. |
Amazing work @inteon in reducing the number of allocs per operation to 1. I did a similar analysis over your change, and saw similar performance. The change should have zero to negligible impact on Kube API server performance. We just have to make sure this new library behaves the same as the existing implementation functionally, which I think existing tests should be able to do(?). |
I'm not sure how detailed the existing tests are at all the edge cases of valid and invalid variants on input (handling of escaped values in keys, whitespace before/after/between tokens, valid and invalid syntax, etc), and byte-for-byte assertions about output. Since this needed to effectively rewrite some of the encoding/decoding paths, we need to make sure we have test coverage for those things. |
Signed-off-by: Tim Ramlot <[email protected]>
There are not enough tests for unicode and escape characters . I have added those tests in #300. Including these new tests, We should detect regression in Serialization and Deserialization code in future. |
Excellent, #300 looks like a great step forward for test coverage of normalized encoding. We'll probably want similar additions for:
|
After upgrading |
Huh⦠did something change on s-m-d master? The latest benchmark update looks like some of the relative improvement came from master getting worse... |
oh, maybe the test changes in #300 impacted the master benchmark numbers |
k/k master is at golang v1.25.1 fyi |
Replaces the
github.com/json-iterator/go
dependency withencoding/json/v2
.Performance is not yet great (feel free to push improvements/ create new PRs based on this PR):
closes #202