Vector isWritable/Reusable/Recyclable APIs #2244
Replies: 6 comments 2 replies
-
Regarding the naming, I like isWritable better than isReusable or isRecyclable because the latter imply we're repurposing a Vector for a new use, however, in the use case I have in mind, we're actively building a Vector and just checking that ensureWritable was called at some point earlier in the process. In the cases of isReusableFlatVector and isRecyclable, we're also trying to avoid calling ensureWritable to avoid allocating more a new Vector, so it makes sense to me semantically. |
Beta Was this translation helpful? Give feedback.
-
This is not true, but prepareForReuse() which is called shortly after in VectorPool could set it to null if it's not mutable (which again isn't checked). |
Beta Was this translation helpful? Give feedback.
-
Illustrating the differences as a table:
|
Beta Was this translation helpful? Give feedback.
-
It doesn't look like those 5 calls or closely related (2 are but they're adjacent) so having a single function vs. just checking both isWritable and isFlat isn't needed to maintain consistency. As long as the StringBuffers check isn't needed. |
Beta Was this translation helpful? Give feedback.
-
@kevinwilfong Thank you for putting this together. Logically, it seems to me that we need only one method that checks if the vector is writable, e.g. recursively singly referenced. There are use cases where we want to only allow for writable vectors of primitive types. In these cases the caller could use isFlatEncoding() && . Hence, I wonder if we can consolidate all these methods into just one with the behavior of the new isWritable. |
Beta Was this translation helpful? Give feedback.
-
It looks like the StringBuffers check was pulled out of SimpleFunctionAdapter, I'll move it back as it only looks like it's needed there #1091 |
Beta Was this translation helpful? Give feedback.
-
This PR #2232 adds a new isWritable API to BaseVector.
There are already isRecyclable and isReusableFlatVector that are in the same spirit, but with stricter requirements designed for different use cases.
Summarizing the 3 APIs:
isWritable
isReusableFlatVector
isRecyclable
Comparing isWritable and isReusableFlatVector, they are very close, isReusableFlatVector just has stricter checks on the encoding (only Flat) and the StringBuffers being unique (I'm unclear on why this is needed). It's easy to see how isReusableFlatVector could be rewritten to use isWritable, or the 5 or so calls could be modified to check isWritable, the encoding, and the StringBuffers are unique, or a helper function outside BaseVector could be written to keep these all in sync but outside the Vector API.
Comparing isWritable and isRecyclable they're more different. Is the values Buffer always non-null? Is the fact it allows the Buffers to not be mutable() an oversight? if the answer to both of these is yes, it's again straightforward to modify the only place this function is used to call isWritable instead and apply the stricter conditions there removing it from the Vector API.
Beta Was this translation helpful? Give feedback.
All reactions