-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance improvement of PrimitiveFloatList by lazy deserialization (…
…#36) Performance improvement of PrimiteFloatList by lazy deserialization Co-authored-by: Sourav Maji <[email protected]>
- Loading branch information
1 parent
a20fd47
commit a31b48f
Showing
4 changed files
with
282 additions
and
28 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
avro-fastserde/src/main/java/com/linkedin/avro/fastserde/CompositeByteBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.linkedin.avro.fastserde; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
public class CompositeByteBuffer { | ||
private int byteBufferCount; | ||
private List<ByteBuffer> byteBuffers; | ||
|
||
public CompositeByteBuffer() { | ||
byteBuffers = new ArrayList<>(2); | ||
} | ||
|
||
public ByteBuffer allocate(int index, int size) { | ||
ByteBuffer byteBuffer; | ||
|
||
// Check if we can reuse the old record's byteBuffers, else allocate a new one. | ||
if (byteBuffers.size() > index && byteBuffers.get(index).capacity() > size) { | ||
byteBuffer = byteBuffers.get(index); | ||
byteBuffer.clear(); | ||
} else { | ||
byteBuffer = ByteBuffer.allocate((int)size).order(ByteOrder.LITTLE_ENDIAN); | ||
} | ||
if (index < byteBuffers.size()) { | ||
byteBuffers.set(index, byteBuffer); | ||
} else { | ||
byteBuffers.add(byteBuffer); | ||
} | ||
return byteBuffer; | ||
} | ||
|
||
public void clear() { | ||
for (ByteBuffer byteBuffer : byteBuffers) { | ||
byteBuffer.clear(); | ||
} | ||
} | ||
|
||
public void setByteBufferCount(int count) { | ||
byteBufferCount = count; | ||
} | ||
|
||
public void setArray(float[] array) { | ||
int k = 0; | ||
for (int i = 0; i < byteBufferCount; i++) { | ||
ByteBuffer byteBuffer = byteBuffers.get(i); | ||
for (int j = 0; j < byteBuffer.limit(); j += Float.BYTES) { | ||
array[k++] = byteBuffer.getFloat(j); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.