Skip to content

Remove allocs from WriteFloat32/WriteFloat64 #234

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

Merged
merged 1 commit into from
Feb 14, 2018
Merged

Remove allocs from WriteFloat32/WriteFloat64 #234

merged 1 commit into from
Feb 14, 2018

Conversation

brian-brazil
Copy link
Contributor

The use of strconv.FormatFloat causes a string allocation,
by setting aside a reusable buffer and using strconv.AppendFloat
this can be avoided.

Before:
BenchmarkRespond-4 300 5392189 ns/op 618936 B/op 20010 allocs/op

After:
BenchmarkRespond-4 300 4713746 ns/op 139744 B/op 10 allocs/op

This benchmark is using a custom encoder that calls WriteFloat64 20k
times, which is the bulk of the work.

The use of strconv.FormatFloat causes a string allocation,
by setting aside a reusable buffer and using strconv.AppendFloat
this can be avoided.

Before:
BenchmarkRespond-4           300           5392189 ns/op          618936 B/op      20010 allocs/op

After:
BenchmarkRespond-4           300           4713746 ns/op          139744 B/op         10 allocs/op

This benchmark is using a custom encoder that calls WriteFloat64 20k
times, which is the bulk of the work.
@codecov
Copy link

codecov bot commented Feb 7, 2018

Codecov Report

Merging #234 into master will decrease coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #234      +/-   ##
==========================================
- Coverage    83.5%   83.46%   -0.04%     
==========================================
  Files          44       44              
  Lines        5500     5505       +5     
==========================================
+ Hits         4593     4595       +2     
- Misses        716      718       +2     
- Partials      191      192       +1
Impacted Files Coverage Δ
feature_stream.go 74.71% <100%> (+0.14%) ⬆️
feature_stream_float.go 100% <100%> (ø) ⬆️
feature_iter_skip.go 75.29% <0%> (-3.53%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 002b5ae...1e8e785. Read the comment docs.

@taowen
Copy link
Contributor

taowen commented Feb 14, 2018

will merge this pr today.

@taowen taowen merged commit 1e8e785 into json-iterator:master Feb 14, 2018
@brian-brazil
Copy link
Contributor Author

Thanks!

@brian-brazil brian-brazil deleted the float-allocs branch February 14, 2018 08:27
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 this pull request may close these issues.

2 participants