-
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(builder): Use z.Allocator for building tables #1576
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.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @ahsanbarkati, @jarifibrahim, and @manishrjain)
table/builder.go, line 251 at r1 (raw file):
defer b.bufLock.Unlock() b.buf.AllocateOffset(int(sz)) b.sz += sz
If you're seeing some issues, then maybe do an assert in a few places about b.sz == LenNoPadding. But, ideally, we shouldn't be using b.sz at all?
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. 1 rules errored during the review.
table/builder.go
Outdated
|
||
func (bb *bblock) Append(data []byte) { | ||
n := copy(bb.data[bb.end:], data) | ||
bb.end += n |
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 n 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.
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
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. 1 rules errored during the review.
levels.go
Outdated
// Expected. | ||
} else if err != nil { | ||
return nil, y.Wrapf(err, "while creating table: %s", fname) | ||
} else { |
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.
Omit unnecessary else when if
doesn't flow into the next statement. 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.
Reviewed 5 of 13 files at r8, 1 of 2 files at r9, 4 of 7 files at r10, 9 of 9 files at r11.
Dismissed @codelingo[bot] from 3 discussions.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ahsanbarkati)
stream_writer.go, line 412 at r11 (raw file):
data := builder.Finish() var err error if tbl, err = table.OpenInMemoryTable(data, fileID, builder.Opts()); err != nil {
might consider passing the builder over to OpenInMemoryTable.
Avoid Go memory spikes by using z.Allocator to allocate blocks during table generation. Also avoid having to copy data over, unless necessary -- instead write the data directly to the mmapped file.
With these changes, we're able to load 1 billion randomly generated 32-byte keys, 128-byte values in 1.5 hrs, with memory usage maxing out to 5 GB.
This change is