-
Notifications
You must be signed in to change notification settings - Fork 1k
Using strings.Builder in golang v1.10 to reduce memory allocations #367
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #367 +/- ##
==========================================
+ Coverage 81.46% 81.78% +0.31%
==========================================
Files 41 41
Lines 5008 5034 +26
==========================================
+ Hits 4080 4117 +37
+ Misses 809 796 -13
- Partials 119 121 +2
Continue to review full report at Codecov.
|
I've checked the issue of codeclimate, it's just facing a bug. The codeclimate has counted the nested function return statement. For the code readability, I think the code should be like this. |
is there any benchmark to support this is actual a improvement? why |
here is a benchmark in the reason why it is faster, you could figure out from the implementation of I'm not sure should I copy the code to I'm working some benchmarks to this PR. |
iter.buf might be reused, so we are decoding from a reader. Cast the buffer to string, will cause the string point to invalid region later. I used the impl in very early days, and fall back to current impl due to the bug introduced. |
hi @taowen , sorry for so long delay. I just made the benchmark to compare before this PR and after. the logs has been a little longer, below. there are two benchmarks cost a little logger time comparing to before. and at the latest two commits, I just move the string factory object to the at last, to answer your question above, I'm not sure I got your point, sorry. but those calling trace might answer your worry. here for any further questions, feel free to comment, I'd like to fix any.
|
hi @taowen , will this be merged or not?! it's been about a week, we really need this improvement. if there is any blur, please comment it. |
|
do you read the implementation of function
Very sorry, since so long there is no more progress about this discussion, I'll just close this PR for no more responsibilities from me. Happy day! |
According issue #240 , there is no reason why we don't, so I've tried.
And we are facing the real problems, the
json.Unmarshal
has been in our service's hot path. TheIterator.ReadString
andIterator.readStringSlowPath
has been called multiple times per second. Any reasonable patch which could reduce the memory allocation will be valuable.I've tried to avoid to use any incompatible trick of Golang. So if there is any plan to support new features of golang v1.10, this PR should be helpful I think.