Extra memory copy in uncompressed writes
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- backend, performance
Research direction
Run the supplied memray reproducer with zarrista, focusing on the ArrayBuilder-created array, the z[:] = arr write, and FilesystemStore. Trace the uncompressed write path and compare peak memory with the Zarr baseline; done means the zarrista run is near 100 MB with no unnecessary extra buffer copy.
Written by the indexing model from the issue text.
Description
With the release of Zarrista 0.1.0 (congrats!) I have been revisiting my benchmarks for measuring zero-copy in Zarr (https://github.com/tomwhite/memray-array). I'm very excited about having a true zero-copy Zarr python library.
Compressed reads and writes incur only a single extra buffer copy (as expected), and uncompressed reads don't incur any extra copies. I don't think that any Zarr python library has achieved zero copy for reads before, so this is great to see!
Only uncompressed writes incur an extra copy - which shouldn't be needed - hence this issue.
To reproduce, run the following
# /// script
# requires-python = ">=3.11"
# dependencies = ["zarrista==0.1.0", "memray", "numpy"]
# ///
import tempfile
import time
from pathlib import Path
import memray
import numpy as np
from memray import FileReader
from zarrista import ArrayBuilder, ChunkGrid, DataType, FillValue
from zarrista.store import FilesystemStore
with tempfile.TemporaryDirectory() as tmp:
profile = str(Path(tmp) / "write.bin")
store = FilesystemStore(tmp)
with memray.Tracker(profile, native_traces=True):
arr = np.random.default_rng().random((5000, 5000), dtype=np.float32)
grid = ChunkGrid.regular(arr.shape, chunk_shape=arr.shape)
dtype = DataType.from_string(np.dtype(arr.dtype).name)
fill_value = FillValue(np.zeros((), dtype=arr.dtype).tobytes())
z = ArrayBuilder(grid, dtype, fill_value).create(store, "/a.zarr")
z[:] = arr
del arr
del z
time.sleep(1)
peak = FileReader(profile).metadata.peak_memory
print(f"peak {peak / 1e6:.1f} MB")
peak 200.7 MB
This should be around 100MB (a single allocation). Compare to Zarr with the default local store which is around 100MB.
# /// script
# requires-python = ">=3.11"
# dependencies = ["zarr==3.3.0", "numcodecs>=0.16.0", "memray", "numpy"]
# ///
import tempfile
import time
from pathlib import Path
import memray
import numpy as np
import zarr
from memray import FileReader
with tempfile.TemporaryDirectory() as tmp:
profile = str(Path(tmp) / "write.bin")
store = str(Path(tmp) / "a.zarr")
with memray.Tracker(profile, native_traces=True):
arr = np.random.default_rng().random((5000, 5000), dtype=np.float32)
z = zarr.create_array(
store=store,
shape=arr.shape,
dtype=arr.dtype,
chunks=arr.shape,
compressors=None,
overwrite=True,
config={"write_empty_chunks": True},
)
z[:] = arr
del arr
del z
time.sleep(1)
peak = FileReader(profile).metadata.peak_memory
print(f"peak {peak / 1e6:.1f} MB")
peak 100.8 MB
cc @LDeakin since this might be getting into Zarrs territory.
- Dominant language
- Python
- Stars
- 52
- Forks
- 3
- Avg merge
- 36m
- Merged PRs (30d)
- 5
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from developmentseed/zarrista
-
Difficulty 4/5 3-5 days Newbie friendliness 54/100
developmentseed/zarrista#222 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
developmentseed/zarrista#211 · 1 comment ·
-
Bump to arrow 60Open
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
developmentseed/zarrista#203 ·
-
Read and write icechunk sessions through the zarr-python Store instead of linking the icechunk crateOpen
Difficulty 5/5 Over a week Newbie friendliness 35/100
developmentseed/zarrista#196 ·
-
pyemscripten wheel is unimportable: the Python layer imports async-only classes unconditionallyOpen
Difficulty 3/5 1-2 days Newbie friendliness 57/100
developmentseed/zarrista#189 · 3 comments ·
All issues in developmentseed/zarrista
Similar issues
-
00 - Bug component: numpy.linalg
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
521xueweihan/HelloGitHub#4543 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
emeryberger/CSrankings#15700 ·
Maintainers usually reply within 2 days
-
Bug | 工作不正常 Triage | 待检查
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
OneDragon-Anything/ZenlessZoneZero-OneDragon#3084 ·
Maintainers usually reply within 1 day
-
Task select patterns with uppercase letters never matchPossibly taken @manobhisriram claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day