Skip to content

Commit 03bd569

Browse files
committed
Avoid memory copy in obstore write
1 parent 3b6565b commit 03bd569

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/zarr/storage/_obstore.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from collections.abc import Iterable
88
from typing import TYPE_CHECKING, Any, TypedDict
99

10+
import numpy as np
11+
1012
from zarr.abc.store import (
1113
ByteRequest,
1214
OffsetByteRequest,
@@ -145,15 +147,15 @@ async def set(self, key: str, value: Buffer) -> None:
145147

146148
self._check_writable()
147149

148-
buf = value.to_bytes()
150+
buf = value.as_numpy_array().view(np.uint8)
149151
await obs.put_async(self.store, key, buf)
150152

151153
async def set_if_not_exists(self, key: str, value: Buffer) -> None:
152154
# docstring inherited
153155
import obstore as obs
154156

155157
self._check_writable()
156-
buf = value.to_bytes()
158+
buf = value.as_numpy_array().view(np.uint8)
157159
with contextlib.suppress(obs.exceptions.AlreadyExistsError):
158160
await obs.put_async(self.store, key, buf, mode="create")
159161

0 commit comments

Comments
 (0)