[Java] Potentially inefficient variable-width vector reallocation
- Dominant language
- Java
- Stars
- 94
- Forks
- 152
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 11
Description
In several places in the Java codebase you can see this kind of pattern:
```java
while (vector.getDataBuffer().capacity() < toCapacity) {
vector.reallocDataBuffer();
}
```
In the event that a much larger capacity is requested, this will spuriously make several reallocations (doubling the capacity each time).
It would probably be more efficient to reallocate directly to satisfy the desired capacity.
Coincidentally, there's a `reallocDataBuffer` overload that seems to do just that.
**Reporter**: [Antoine Pitrou](https://issues.apache.org/jira/browse/ARROW-17919) / @pitrou
**Note**: *This issue was originally created as [ARROW-17919](https://issues.apache.org/jira/browse/ARROW-17919). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*
Contributor guide
Research direction
Start by locating the Java call sites that loop on vector.getDataBuffer().capacity() and call reallocDataBuffer(), then inspect the reallocDataBuffer overload that accepts a desired capacity. Update the affected paths so a requested larger capacity is satisfied directly, and verify the relevant Java tests cover the reallocation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100