Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data] Optimization to reduce ArrowBlock building time for blocks of size 1 #38833

Merged
merged 2 commits into from
Aug 26, 2023

Conversation

stephanie-wang
Copy link
Contributor

@stephanie-wang stephanie-wang commented Aug 24, 2023

Why are these changes needed?

Many Data ops depend on converting numpy batches to Arrow blocks. A single np array -> pyarrow is normally zero-copy, but blocks with multiple rows will need a copy to make the column of np arrays into one contiguous ndarray. This PR avoids this step for blocks of a single row by using np.expand_dims to reshape the array instead of copying it.

Related issue number

Needed for #37474.

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: Stephanie Wang <swang@cs.berkeley.edu>
@stephanie-wang
Copy link
Contributor Author

For a single-row block [{"field": 100MB np.array}]:

Before:
In [11]: %timeit b.build()
385 ms ± 8.88 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

After:
In [13]: %timeit b.build()
116 µs ± 3.59 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

@ericl
Copy link
Contributor

ericl commented Aug 24, 2023 via email

Copy link
Contributor

@c21 c21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stephanie-wang stephanie-wang added the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Aug 24, 2023
@zhe-thoughts
Copy link
Collaborator

Please verify tests-ok and then I will review / merge. Thanks!

@stephanie-wang stephanie-wang added tests-ok The tagger certifies test failures are unrelated and assumes personal liability. and removed @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. labels Aug 24, 2023
@stephanie-wang
Copy link
Contributor Author

Hey @zhe-thoughts this is ready to merge.

@zhe-thoughts
Copy link
Collaborator

"buildkite/premerge" is a x

@stephanie-wang
Copy link
Contributor Author

"buildkite/premerge" is a x

The failure is unrelated (it's flaky on master)

@c21
Copy link
Contributor

c21 commented Aug 25, 2023

I guess buildkite/premerge is mandatory to pass before merging. Let me retry it.

@zhe-thoughts
Copy link
Collaborator

Yes other checks we can use manual judgement, buildkite/premerge must pass. cc @aslonnie

@stephanie-wang
Copy link
Contributor Author

Yes other checks we can use manual judgement, buildkite/premerge must pass. cc @aslonnie

It's passing now.

@stephanie-wang stephanie-wang merged commit 621ef89 into ray-project:master Aug 26, 2023
51 of 54 checks passed
@stephanie-wang stephanie-wang deleted the optimize-one-record branch August 26, 2023 01:18
stephanie-wang added a commit to stephanie-wang/ray that referenced this pull request Aug 28, 2023
…size 1 ray-project#38833

Many Data ops depend on converting numpy batches to Arrow blocks. A single np array -> pyarrow is normally zero-copy, but blocks with multiple rows will need a copy to make the column of np arrays into one contiguous ndarray. This PR avoids this step for blocks of a single row by using np.expand_dims to reshape the array instead of copying it.

Signed-off-by: Stephanie Wang <swang@cs.berkeley.edu>
GeneDer pushed a commit that referenced this pull request Aug 28, 2023
…size 1 #38833 (#38988)

Many Data ops depend on converting numpy batches to Arrow blocks. A single np array -> pyarrow is normally zero-copy, but blocks with multiple rows will need a copy to make the column of np arrays into one contiguous ndarray. This PR avoids this step for blocks of a single row by using np.expand_dims to reshape the array instead of copying it.

Signed-off-by: Stephanie Wang <swang@cs.berkeley.edu>
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
…size 1 ray-project#38833

Many Data ops depend on converting numpy batches to Arrow blocks. A single np array -> pyarrow is normally zero-copy, but blocks with multiple rows will need a copy to make the column of np arrays into one contiguous ndarray. This PR avoids this step for blocks of a single row by using np.expand_dims to reshape the array instead of copying it.

Signed-off-by: Stephanie Wang <swang@cs.berkeley.edu>
Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
LeonLuttenberger pushed a commit to jaidisido/ray that referenced this pull request Sep 5, 2023
…size 1 ray-project#38833

Many Data ops depend on converting numpy batches to Arrow blocks. A single np array -> pyarrow is normally zero-copy, but blocks with multiple rows will need a copy to make the column of np arrays into one contiguous ndarray. This PR avoids this step for blocks of a single row by using np.expand_dims to reshape the array instead of copying it.

Signed-off-by: Stephanie Wang <swang@cs.berkeley.edu>
jimthompson5802 pushed a commit to jimthompson5802/ray that referenced this pull request Sep 12, 2023
…size 1 ray-project#38833

Many Data ops depend on converting numpy batches to Arrow blocks. A single np array -> pyarrow is normally zero-copy, but blocks with multiple rows will need a copy to make the column of np arrays into one contiguous ndarray. This PR avoids this step for blocks of a single row by using np.expand_dims to reshape the array instead of copying it.

Signed-off-by: Stephanie Wang <swang@cs.berkeley.edu>
Signed-off-by: Jim Thompson <jimthompson5802@gmail.com>
vymao pushed a commit to vymao/ray that referenced this pull request Oct 11, 2023
…size 1 ray-project#38833

Many Data ops depend on converting numpy batches to Arrow blocks. A single np array -> pyarrow is normally zero-copy, but blocks with multiple rows will need a copy to make the column of np arrays into one contiguous ndarray. This PR avoids this step for blocks of a single row by using np.expand_dims to reshape the array instead of copying it.

Signed-off-by: Stephanie Wang <swang@cs.berkeley.edu>
Signed-off-by: Victor <vctr.y.m@example.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests-ok The tagger certifies test failures are unrelated and assumes personal liability.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants