Repository navigation
estimate_chunksize without allocations - #332
Merged
Merged
Conversation
estimate_chunksize is what eachchunk returns for any array that is not a DiskArray, so it runs for every view taken of an in-memory array by packages that track chunks (YAXArrays rebuilds its chunk grid on every getindex). It collected the size tuple into a Vector for cumprod, called ntuple with a runtime length, and computed a clamp it never used: 292 ns and 10 allocations for a 3-d array. Doing the same arithmetic on tuples with the dimension count known at compile time gives the identical GridChunks in 9 ns with no allocations. Tests cover a 3-d case where the limit falls inside the middle dimension and assert zero allocations. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
meggart
approved these changes
Oct 7, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
estimate_chunksizeis whateachchunkreturns for any array that is not aDiskArray, so it runs for every view taken of an in-memory array by packages that track chunks; YAXArrays rebuilds its chunk grid on everygetindex, and it was the largest remaining cost in JuliaDataCubes/YAXArrays.jl#361 after the YAXArrays-side fixes.It collected the size tuple into a
Vectorforcumprod, calledntuplewith a runtime length (so the closure was not specialised), and computed aclampwhose result was never used: 292 ns and 10 allocations for a 3-d array. The same arithmetic on tuples, with the dimension count known at compile time, gives the identicalGridChunksin 9 ns with no allocations:Tests: the existing
estimate_chunksizecases are unchanged; added a 3-d case where the element limit falls inside the middle dimension, and assertions thatestimate_chunksizeandeachchunkof a view allocate nothing.🤖 Generated with Claude Code