Skip to content
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

raft: avoid allocation of Raft entry due to logging #10680

Merged
merged 1 commit into from
Apr 28, 2019

Conversation

nvanbenschoten
Copy link
Contributor

raftpb.Entry.String takes a pointer receiver, so calling it
on a loop variable was causing the variable to escape. Removing
the .String() call was enough to avoid the allocation, but
this also avoids a memory copy and prevents similar bugs.

This was responsible for 11.63% of total allocations in an
experiment with https://github.com/nvanbenschoten/raft-toy.

Please read https://github.com/etcd-io/etcd/blob/master/CONTRIBUTING.md#contribution-flow.

@nvanbenschoten
Copy link
Contributor Author

cc. @bdarnell

`raftpb.Entry.String` takes a pointer receiver, so calling it
on a loop variable was causing the variable to escape. Removing
the `.String()` call was enough to avoid the allocation, but
this also avoids a memory copy and prevents similar bugs.

This was responsible for 11.63% of total allocations in an
experiment with https://github.com/nvanbenschoten/raft-toy.
@codecov-io
Copy link

Codecov Report

Merging #10680 into master will decrease coverage by 0.17%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10680      +/-   ##
==========================================
- Coverage   71.63%   71.46%   -0.18%     
==========================================
  Files         394      394              
  Lines       36658    36659       +1     
==========================================
- Hits        26261    26197      -64     
- Misses       8564     8619      +55     
- Partials     1833     1843      +10
Impacted Files Coverage Δ
raft/raft.go 91.55% <100%> (-0.64%) ⬇️
pkg/fileutil/purge.go 65.9% <0%> (-6.82%) ⬇️
etcdserver/apply.go 82.97% <0%> (-5.9%) ⬇️
proxy/grpcproxy/watcher.go 85.71% <0%> (-4.09%) ⬇️
etcdserver/v2_server.go 80.76% <0%> (-3.85%) ⬇️
etcdserver/util.go 95% <0%> (-3.75%) ⬇️
proxy/grpcproxy/watch.go 89.75% <0%> (-3.02%) ⬇️
clientv3/balancer/balancer.go 84.25% <0%> (-2.37%) ⬇️
lease/leasehttp/http.go 64.23% <0%> (-1.46%) ⬇️
pkg/schedule/schedule.go 81.69% <0%> (-1.41%) ⬇️
... and 22 more

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 cca0d5c...24f35a9. Read the comment docs.

@xiang90
Copy link
Contributor

xiang90 commented Apr 28, 2019

lgtm

@xiang90 xiang90 merged commit efcc108 into etcd-io:master Apr 28, 2019
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/appendAlloc branch April 28, 2019 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants