Optimize ser/de to avoid using output stream#9278
Merged
Jackie-Jiang merged 2 commits intoapache:masterfrom Aug 25, 2022
Merged
Optimize ser/de to avoid using output stream#9278Jackie-Jiang merged 2 commits intoapache:masterfrom
Jackie-Jiang merged 2 commits intoapache:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9278 +/- ##
=============================================
- Coverage 69.93% 15.33% -54.61%
+ Complexity 5009 168 -4841
=============================================
Files 1861 1811 -50
Lines 99222 97124 -2098
Branches 15092 14861 -231
=============================================
- Hits 69394 14895 -54499
- Misses 24916 81096 +56180
+ Partials 4912 1133 -3779
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
| } | ||
| } catch (IOException e) { | ||
| throw new RuntimeException("Caught exception while serializing Map", e); | ||
| long bufferSize = (3 + 2 * (long) size) * Integer.BYTES; |
Contributor
There was a problem hiding this comment.
(nit) suggest giving a brief comment (for future readers) on what 3 and 2 means. I think
3 -> size, keyTypeValue, valueTypeValue
2-> keyBytes.length, valueBytes.length
siddharthteotia
approved these changes
Aug 25, 2022
This file contains hidden or 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
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.
Avoid using
ByteArrayOutputStreamwhich will potentially copy bytes multiple times (during expand and finaltoByteArray()). Pre-calculate the buffer size required, and then create the buffer only once.Before optimization
BenchmarkObjectSerDe.bytesSet avgt 5 557.718 ± 31.501 ms/op
BenchmarkObjectSerDe.stringList avgt 5 1089.643 ± 30.302 ms/op
BenchmarkObjectSerDe.stringSet avgt 5 1061.030 ± 98.827 ms/op
BenchmarkObjectSerDe.stringToStringMap avgt 5 1947.736 ± 29.011 ms/op
After optimization
BenchmarkObjectSerDe.bytesSet avgt 5 360.085 ± 10.518 ms/op
BenchmarkObjectSerDe.stringList avgt 5 911.377 ± 35.301 ms/op
BenchmarkObjectSerDe.stringSet avgt 5 920.723 ± 29.300 ms/op
BenchmarkObjectSerDe.stringToStringMap avgt 5 1699.881 ± 165.362 ms/op