Skip to content

Conversation

@d-v-b
Copy link
Contributor

@d-v-b d-v-b commented Feb 12, 2026

removes an expensive isinstance check inside BytesCodec._decode_single. Isinstance on runtime_checkable protocols is expensive and this particular check is in a hotspot. Without the check, we are slightly less type-safe, but users who somehow get a non-ndarray into this part of the code will get an immediate a runtime error.

@d-v-b d-v-b added the performance Potential issues with Zarr performance (I/O, memory, etc.) label Feb 12, 2026
@github-actions github-actions bot added the needs release notes Automatically applied to PRs which haven't added release notes label Feb 12, 2026
@d-v-b d-v-b added the benchmark Code will be benchmarked in a CI job. label Feb 12, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 12, 2026

Merging this PR will improve performance by 34.44%

⚡ 31 improved benchmarks
✅ 17 untouched benchmarks
⏩ 6 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_slice_indexing[None-(slice(0, None, 4), slice(0, None, 4), slice(0, None, 4))-memory_get_latency] 555.2 ms 425.9 ms +30.37%
WallTime test_slice_indexing[None-(slice(10, -10, 4), slice(10, -10, 4), slice(10, -10, 4))-memory] 274.6 ms 205.1 ms +33.88%
WallTime test_slice_indexing[None-(slice(None, None, None), slice(0, 3, 2), slice(0, 10, None))-memory_get_latency] 5.2 ms 4.1 ms +26.75%
WallTime test_slice_indexing[None-(slice(10, -10, 4), slice(10, -10, 4), slice(10, -10, 4))-memory_get_latency] 304.4 ms 233.2 ms +30.54%
WallTime test_slice_indexing[None-(slice(None, 10, None), slice(None, 10, None), slice(None, 10, None))-memory] 1,007.5 µs 891.1 µs +13.07%
WallTime test_slice_indexing[(50, 50, 50)-(slice(None, None, None), slice(None, None, None), slice(None, None, None))-memory_get_latency] 567.1 ms 439.6 ms +28.99%
WallTime test_read_array[memory-Layout(shape=(1000000,), chunks=(1000,), shards=None)-None] 372.3 ms 276.9 ms +34.44%
WallTime test_slice_indexing[(50, 50, 50)-(0, 0, 0)-memory] 2 ms 1.8 ms +10.97%
WallTime test_slice_indexing[(50, 50, 50)-(slice(0, None, 4), slice(0, None, 4), slice(0, None, 4))-memory] 546 ms 416.2 ms +31.2%
WallTime test_read_array[memory-Layout(shape=(1000000,), chunks=(1000,), shards=(1000,))-gzip] 1.5 s 1.3 s +14.58%
WallTime test_slice_indexing[(50, 50, 50)-(slice(0, None, 4), slice(0, None, 4), slice(0, None, 4))-memory_get_latency] 563.9 ms 433.4 ms +30.12%
WallTime test_slice_indexing[(50, 50, 50)-(slice(None, None, None), slice(0, 3, 2), slice(0, 10, None))-memory] 7.6 ms 6.3 ms +21.79%
WallTime test_read_array[memory-Layout(shape=(1000000,), chunks=(1000,), shards=None)-gzip] 681.8 ms 584 ms +16.75%
WallTime test_slice_indexing[(50, 50, 50)-(slice(None, None, None), slice(None, None, None), slice(None, None, None))-memory] 551.2 ms 421.9 ms +30.64%
WallTime test_slice_indexing[(50, 50, 50)-(slice(None, None, None), slice(0, 3, 2), slice(0, 10, None))-memory_get_latency] 8.5 ms 7.2 ms +18.34%
WallTime test_read_array[memory-Layout(shape=(1000000,), chunks=(100,), shards=(1000000,))-None] 3.8 s 2.9 s +32.39%
WallTime test_slice_indexing[None-(slice(None, None, None), slice(0, 3, 2), slice(0, 10, None))-memory] 4.8 ms 3.7 ms +28.66%
WallTime test_slice_indexing[(50, 50, 50)-(slice(10, -10, 4), slice(10, -10, 4), slice(10, -10, 4))-memory_get_latency] 316.7 ms 244.6 ms +29.5%
WallTime test_read_array[memory-Layout(shape=(1000000,), chunks=(1000,), shards=(1000,))-None] 1,162.3 ms 975.1 ms +19.2%
WallTime test_slice_indexing[None-(slice(0, None, 4), slice(0, None, 4), slice(0, None, 4))-memory] 502.8 ms 374.1 ms +34.39%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.


Comparing d-v-b:perf/remove-isinstance-check (f0d4b2e) with main (3e7d24d)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@d-v-b
Copy link
Contributor Author

d-v-b commented Feb 12, 2026

35% perf improvement seems good

@d-v-b d-v-b requested a review from jhamman February 12, 2026 19:02
@d-v-b d-v-b changed the title perf/remove isinstance check perf:remove isinstance check Feb 12, 2026
@github-actions github-actions bot removed the needs release notes Automatically applied to PRs which haven't added release notes label Feb 12, 2026
@d-v-b d-v-b requested a review from dcherian February 12, 2026 21:01
dtype = replace(chunk_spec.dtype, endianness=endian_str).to_native_dtype() # type: ignore[call-arg]
else:
dtype = chunk_spec.dtype.to_native_dtype()
as_array_like = chunk_bytes.as_array_like()
Copy link
Contributor

Choose a reason for hiding this comment

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

can we just have as_array_like become as_ndarray_like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark Code will be benchmarked in a CI job. performance Potential issues with Zarr performance (I/O, memory, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants