-
-
Notifications
You must be signed in to change notification settings - Fork 329
Avoid memory copy in obstore write #2972
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
Merged
d-v-b
merged 9 commits into
zarr-developers:main
from
tomwhite:avoid-mem-copy-in-obstore-write
May 14, 2025
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
03bd569
Avoid memory copy in obstore write
tomwhite ce25ec3
Add as_bytes_like method to Buffer
tomwhite a48b8bd
Add changelog entry
tomwhite 40bc156
Merge branch 'main' into avoid-mem-copy-in-obstore-write
jakirkham 4a837c0
Merge branch 'main' into avoid-mem-copy-in-obstore-write
d-v-b 94e693e
Merge branch 'main' into avoid-mem-copy-in-obstore-write
d-v-b bf3c713
No need to take unsigned bytes view following #2738
tomwhite 5683b24
Change method name to `as_buffer_like`
tomwhite a15be8c
Merge branch 'main' into avoid-mem-copy-in-obstore-write
tomwhite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worthwhile to make this a standard method? This would make it easier to use throughout the codebase
Some possible names:
to_bytelike
to_binary
to_uint8s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess i'm also curious to know why we have a
to_bytes()
method that makes a copy, when.as_numpy_array().view(np.uint8)
achieves the same effective result (an iterable of bytes) without a copy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was suggested in #2925, so I've added an
as_bytes_like
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bytes
objects always own their memory. So creating a newbytes
object means making a copyIf we prefer to move away from this approach, we could add a deprecation cycle to move from
to_bytes
toas_bytes_like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
FsspecStore
works withBytesLike
since it didn't accept amemoryview
object when I tried it. So we probably need to keepto_bytes()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this would be a good issue to raise with
fsspec
if we can reproduce with it directlyIf not, a Zarr issue would be welcome
Ideally these copies should be avoidable in the
FsspecStore
case as wellEdit: Ofc this is non-blocking, just would like to improve the performance in all cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened fsspec/s3fs#959
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also suggest
as_buffer_like
, because in my head "bytes" in Python is a type that always owns its own memory, while "buffer" doesn't necessarily own its memory, as in the buffer protocol orcollections.abc.Buffer
.