ARROW-1547: [JAVA] Fix 8x memory over-allocation in BitVector#1109
Closed
siddharthteotia wants to merge 2 commits intoapache:masterfrom
Closed
ARROW-1547: [JAVA] Fix 8x memory over-allocation in BitVector#1109siddharthteotia wants to merge 2 commits intoapache:masterfrom
siddharthteotia wants to merge 2 commits intoapache:masterfrom
Conversation
Contributor
Author
icexelloss
reviewed
Sep 19, 2017
|
|
||
| int valueCount; | ||
| private int allocationSizeInBytes = INITIAL_VALUE_ALLOCATION; | ||
| private int allocationSizeInBytes = getSizeFromCount(INITIAL_VALUE_ALLOCATION); |
Contributor
There was a problem hiding this comment.
Do we want to fix reset() as well?
Contributor
Author
There was a problem hiding this comment.
Yes done. Thanks @icexelloss for pointing out.
Member
|
+1 |
pribor
pushed a commit
to GlobalWebIndex/arrow
that referenced
this pull request
Oct 24, 2025
Problem: Typically there are 3 ways of specifying the amount of memory needed for vectors. CASE (1) allocateNew() – here the application doesn't really specify the size of memory or value count. Each vector type has a default value count (4096) and therefore a default size (in bytes) is used in such cases. For example, for a 4 byte fixed-width vector, we will allocate 32KB of memory for a call to allocateNew(). CASE (2) setInitialCapacity(count) followed by allocateNew() - In this case also the application doesn't specify the value count or size in allocateNew(). However, the call to setInitialCapacity() dictates the amount of memory the subsequent call to allocateNew() will allocate. For example, we can do setInitialCapacity(1024) and the call to allocateNew() will allocate 4KB of memory for the 4 byte fixed-width vector. CASE (3) allocateNew(count) - The application is specific about requirements. For nullable vectors, the above calls also allocate the memory for validity vector. The problem is that Bit Vector uses a default memory size in bytes of 4096. In other words, we allocate a vector for 4096*8 value count. In the default case (as explained above), the vector types have a value count of 4096 so we need only 4096 bits (512 bytes) in the bit vector and not really 4096 as the size in bytes. This happens in CASE 1 where the application depends on the default memory allocation . In such cases, the size of buffer for bit vector is 8x than actually needed Author: siddharth <[email protected]> Closes apache#1109 from siddharthteotia/ARROW-1547 and squashes the following commits: c92164a [siddharth] addressed review comments f3d1234 [siddharth] ARROW-1547: Fix 8x memory over-allocation in BitVector
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
Typically there are 3 ways of specifying the amount of memory needed for vectors.
CASE (1) allocateNew() – here the application doesn't really specify the size of memory or value count. Each vector type has a default value count (4096) and therefore a default size (in bytes) is used in such cases.
For example, for a 4 byte fixed-width vector, we will allocate 32KB of memory for a call to allocateNew().
CASE (2) setInitialCapacity(count) followed by allocateNew() - In this case also the application doesn't specify the value count or size in allocateNew(). However, the call to setInitialCapacity() dictates the amount of memory the subsequent call to allocateNew() will allocate.
For example, we can do setInitialCapacity(1024) and the call to allocateNew() will allocate 4KB of memory for the 4 byte fixed-width vector.
CASE (3) allocateNew(count) - The application is specific about requirements.
For nullable vectors, the above calls also allocate the memory for validity vector.
The problem is that Bit Vector uses a default memory size in bytes of 4096. In other words, we allocate a vector for 4096*8 value count.
In the default case (as explained above), the vector types have a value count of 4096 so we need only 4096 bits (512 bytes) in the bit vector and not really 4096 as the size in bytes.
This happens in CASE 1 where the application depends on the default memory allocation . In such cases, the size of buffer for bit vector is 8x than actually needed