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

GH-41: BaseVariableWidthViewVector setZero only if necessary #557

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -1367,11 +1367,13 @@ protected ArrowBuf allocateOrGetLastDataBuffer(int length) {
protected final void setBytes(int index, byte[] value, int start, int length) {
int writePosition = index * ELEMENT_SIZE;

// to clear the memory segment of view being written to
// this is helpful in case of overwriting the value
viewBuffer.setZero(writePosition, ELEMENT_SIZE);

if (length <= INLINE_SIZE) {
// Check if the memory segment has been written, and clear it if it has been set.
// It is recommended to batch initialize the viewBuffer before setBytes.
if (viewBuffer.getLong(writePosition) != 0 || viewBuffer.getLong(writePosition + 8) != 0) {
Copy link
Member

Choose a reason for hiding this comment

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

So the basic effect is that if the view buffer is all 0, we skip setting it back to 0? And basically, for freshly allocated memory, this skips a redundant memset? Can we explain it a little more in the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's redundant to setZero if the data is already zero. Checking will introduce some overhead, but it is much smaller than that of setMemory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update in 16c9e2f

Copy link
Member

Choose a reason for hiding this comment

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

Is it safe to check only these positions? IIUC, ZERO is a valid value to be set.

Copy link
Member

Choose a reason for hiding this comment

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

But if all 16 bytes are 0, there is no need to set them to 0 again, I think is the point.

viewBuffer.setZero(writePosition, ELEMENT_SIZE);
}

// allocate inline buffer
// set length
viewBuffer.setInt(writePosition, length);
Expand Down Expand Up @@ -1411,11 +1413,13 @@ protected final void setBytes(int index, byte[] value, int start, int length) {
protected final void setBytes(int index, ArrowBuf valueBuf, int start, int length) {
int writePosition = index * ELEMENT_SIZE;

// to clear the memory segment of view being written to
// this is helpful in case of overwriting the value
viewBuffer.setZero(writePosition, ELEMENT_SIZE);

if (length <= INLINE_SIZE) {
// Check if the memory segment has been written, and clear it if it has been set.
// It is recommended to batch initialize the viewBuffer before setBytes.
if (viewBuffer.getLong(writePosition) != 0 || viewBuffer.getLong(writePosition + 8) != 0) {
viewBuffer.setZero(writePosition, ELEMENT_SIZE);
}

// allocate inline buffer
// set length
viewBuffer.setInt(writePosition, length);
Expand Down
Loading