-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
opt(memory): Use z.Calloc for allocating KVList #1563
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 26 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 26 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 27 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 26 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 26 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 26 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 26 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issues found. 21 rules errored during the review.
stream.go
Outdated
@@ -175,17 +203,21 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error { | |||
streamId := atomic.AddUint32(&st.nextStreamId, 1) | |||
|
|||
outList := new(pb.KVList) | |||
outList.AllocatorId = st.newAllocator(threadId).Ref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize outList using a composite literal to simplify the code. as specified in Effective Go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issues found. 22 rules errored during the review.
stream.go
Outdated
@@ -175,6 +202,7 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error { | |||
streamId := atomic.AddUint32(&st.nextStreamId, 1) | |||
|
|||
outList := new(pb.KVList) | |||
outList.AllocatorId = st.newAllocator(threadId).Ref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize outList using a composite literal to simplify the code. as specified in Effective Go
Add an --encryption-key-file flag to the badger stream tool to support encrypted databases. Changes: * Add --encryption-key-file flag * Set block and index cache sizes to fix panic when running stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 issues found. 1 rules errored during the review.
@@ -175,6 +206,7 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error { | |||
streamId := atomic.AddUint32(&st.nextStreamId, 1) | |||
|
|||
outList := new(pb.KVList) | |||
outList.AllocRef = st.newAllocator(threadId).Ref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize outList using a composite literal to simplify the code. as specified in Effective Go
@@ -50,7 +52,10 @@ type collector struct { | |||
} | |||
|
|||
func (c *collector) Send(list *bpb.KVList) error { | |||
c.kv = append(c.kv, list.Kv...) | |||
for _, kv := range list.Kv { | |||
cp := proto.Clone(kv).(*bpb.KV) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unchecked type assertions can cause panics. Check for success with the x, ok := y.(type) style.
@@ -175,6 +206,7 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error { | |||
streamId := atomic.AddUint32(&st.nextStreamId, 1) | |||
|
|||
outList := new(pb.KVList) | |||
outList.AllocRef = st.newAllocator(threadId).Ref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize outList using a composite literal to simplify the code. as specified in Effective Go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 issues found. 1 rules errored during the review.
@@ -175,6 +206,7 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error { | |||
streamId := atomic.AddUint32(&st.nextStreamId, 1) | |||
|
|||
outList := new(pb.KVList) | |||
outList.AllocRef = st.newAllocator(threadId).Ref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize outList using a composite literal to simplify the code. as specified in Effective Go
@@ -50,7 +52,10 @@ type collector struct { | |||
} | |||
|
|||
func (c *collector) Send(list *bpb.KVList) error { | |||
c.kv = append(c.kv, list.Kv...) | |||
for _, kv := range list.Kv { | |||
cp := proto.Clone(kv).(*bpb.KV) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unchecked type assertions can cause panics. Check for success with the x, ok := y.(type) style.
@@ -175,6 +206,7 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error { | |||
streamId := atomic.AddUint32(&st.nextStreamId, 1) | |||
|
|||
outList := new(pb.KVList) | |||
outList.AllocRef = st.newAllocator(threadId).Ref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize outList using a composite literal to simplify the code. as specified in Effective Go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found. 1 rules errored during the review.
} | ||
return nil | ||
// Mark the stream as done. | ||
outList.Kv = append(outList.Kv, &pb.KV{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize outList using a composite literal to simplify the code. as specified in Effective Go
} | ||
return nil | ||
// Mark the stream as done. | ||
outList.Kv = append(outList.Kv, &pb.KV{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize outList using a composite literal to simplify the code. as specified in Effective Go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 1 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 3 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 7 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 16 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 11 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 21 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 21 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 1 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 4 rules errored during the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 12 rules errored during the review.
KVs can take up a lot of memory in the stream framework. With this change, we allocate them using z.Allocator and release them after the final KVList is sent out.
This change is