-
Notifications
You must be signed in to change notification settings - Fork 357
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
fix: always copy once after top get #577
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #577 +/- ##
==========================================
- Coverage 78.57% 74.26% -4.32%
==========================================
Files 69 63 -6
Lines 10823 8435 -2388
==========================================
- Hits 8504 6264 -2240
+ Misses 1942 1830 -112
+ Partials 377 341 -36 ☔ View full report in Codecov by Sentry. |
chenzhuoyu
approved these changes
Jan 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
sonic.Get()
does copy the entired JSON and refer it to returned partial json. This behavior is neither CPU-friendly nor memory-safe: Copy entire JSON is time consuming, and returned JSON consumes more memory especially if it is cached or hold for a long term. Thus, We decide to not copy input JSON bytes, but copy returned partial JSON instead.What's the effect
After this change, most normal services may gain a little CPU improve on
sonic.Get()
, and cache-like services will be less possible to be OOM.Only problem is for services who exists data-race on input JSON bytes, the panic may be more frequent. However, we believe this is a rare case in practice, and we DONOT expect any data race on input JSON.