Skip to content

[feat][cp] Allow transferring a vector to a given memory pool#489

Open
Weixin-Xu wants to merge 3 commits intobytedance:mainfrom
Weixin-Xu:transferOrCopy
Open

[feat][cp] Allow transferring a vector to a given memory pool#489
Weixin-Xu wants to merge 3 commits intobytedance:mainfrom
Weixin-Xu:transferOrCopy

Conversation

@Weixin-Xu
Copy link
Copy Markdown
Collaborator

@Weixin-Xu Weixin-Xu commented Apr 8, 2026

Summary:

This diff adds an API BaseVector::transferOrCopyTo(MemoryPool* pool) to allow transferring the ownership of a vector to a target memory pool. If a buffer in this vector cannot be transferred (e.g., BufferView), it is copied to the target pool. After the call, the vector is entirely owned by the new pool such that the original pool can be destructed even if this vector is not released yet. (Note that this API transfers a buffer to the target pool even if it's multiply referenced.)

from facebookincubator/velox#13814

What problem does this PR solve?

Issue Number: close #xxx

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 🚀 Performance improvement (optimization)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
  • 🔨 Refactoring (no logic changes)
  • 🔧 Build/CI or Infrastructure changes
  • 📝 Documentation only

Description

Describe your changes in detail.
For complex logic, explain the "Why" and "How".

Performance Impact

  • No Impact: This change does not affect the critical path (e.g., build system, doc, error handling).

  • Positive Impact: I have run benchmarks.

    Click to view Benchmark Results
    Paste your google-benchmark or TPC-H results here.
    Before: 10.5s
    After:   8.2s  (+20%)
    
  • Negative Impact: Explained below (e.g., trade-off for correctness).

Release Note

Please describe the changes in this PR

Release Note:

Release Note:
- Fixed a crash in `substr` when input is null.
- optimized `group by` performance by 20%.

Checklist (For Author)

  • I have added/updated unit tests (ctest).
  • I have verified the code with local build (Release/Debug).
  • I have run clang-format / linters.
  • (Optional) I have run Sanitizers (ASAN/TSAN) locally for complex C++ changes.
  • No need to test or manual test.

Breaking Changes

  • No

  • Yes (Description: ...)

    Click to view Breaking Changes
    Breaking Changes:
    - Description of the breaking change.
    - Possible solutions or workarounds.
    - Any other relevant information.
    

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 8, 2026

CLA assistant check
All committers have signed the CLA.

Summary:

This diff adds an API `BaseVector::transferOrCopyTo(MemoryPool* pool)` to allow
transferring the ownership of a vector to a target memory pool. If a buffer in this
vector cannot be transferred (e.g., BufferView), it is copied to the target pool. After
the call, the vector is entirely owned by the new pool such that the original pool can
be destructed even if this vector is not released yet. (Note that this API transfers a
buffer to the target pool even if it's multiply referenced.)

from facebookincubator/velox#13814
…buffers are copied

Summary:

FlatVector::transferOrCopyTo() and ConstantVector::transferOrCopyTo() may copy the string
buffers to new ones. However, there was a bug that they didn't udpate the StringViews in the
vectors afterwards. StringViews must be updated if a string buffer is replaced by its copy,
because StringViews contain pointers to addresses inside the string buffers.

This diff updates StringViews in FlatVector::transferOrCopyTo() and
ConstantVector::transferOrCopyTo() when a copy of a string buffer occurs. It also updated the
unit test to cover these situations.

In addition, this diff adds documentation of the BaseVector::transferOrCopyTo() API. It also
removes FlatMapVector::transferOrCopyTo() since it's not covered in the unit test yet.

from facebookincubator/velox#15489
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants