Restore optimizations for NDBuffer.all_equal
#2730
Draft
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.
Zarr 3.x has some performance regressions for certain write workloads (writing large chunks with floating point dtype).
This change modifies the implementation of
NDBuffer.all_equal
to be the same logic as Zarr 2.x'szarr.util.all_equals
, which contains a number of important optimizations. A few mechanical changes were made to accomodate that the subroutine is now a method ofNDBuffer
rather than function.This change is most impactful when writing large floating point chunks as the implementation of
is significantly more efficient than calling
since
np.broadcast
requires potentially a large allocation -- the size of `self.data -- and then np.array_equal needs to fetch double the number of cache lines.On EC2 r7i.2xlarge:
(Both numbers are faster on M3 Max but similar slowdown).
With low-latency stores (e.g. local SSD), this results in double-digit % speed-ups for the workload referenced in the Zarr V3 blog post:
For higher latency stores, improvement is still dramatic (10%+) when chunks have high compression ratios (e.g. np.ones).
For arrays larger than 1 GB, improvement is even more pronounced.
Towards #2710