Skip to content
Merged
Changes from 1 commit
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) {
// to clear the memory segment of view being written to
// if it has been set
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.

Copy link
Member

Choose a reason for hiding this comment

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

@wgtmac are we on the same page here?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it sounds good.

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) {
// to clear the memory segment of view being written to
// if it has been set
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