Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions log_unstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,12 @@ func (u *unstable) stableTo(id entryID) {
// potentially large entries that aren't needed anymore. Simply clearing the
// entries wouldn't be safe because clients might still be using them.
func (u *unstable) shrinkEntriesArray() {
// We replace the array if we're using less than half of the space in
// it. This number is fairly arbitrary, chosen as an attempt to balance
// memory usage vs number of allocations. It could probably be improved
// with some focused tuning.
// TODO: revisit shrinking. Using len/cap wasn't useful since
// stableTo slices the entries. It might be better to shrink
// based on the actual size of the retained entries instead.
const lenMultiple = 2
Comment on lines +171 to 174

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have plan to spend too much effort to optimize this. Let's just keep it as simple as possible.

Suggested change
// TODO: revisit shrinking. Using len/cap wasn't useful since
// stableTo slices the entries. It might be better to shrink
// based on the actual size of the retained entries instead.
const lenMultiple = 2

if len(u.entries) == 0 {
u.entries = nil
} else if len(u.entries)*lenMultiple < cap(u.entries) {
newEntries := make([]*pb.Entry, len(u.entries))
copy(newEntries, u.entries)
u.entries = newEntries
}
}

Expand Down