You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, ZGroup opens a group immediately and recursively, which causes performance issues, especially when the group contains a large number of subarrays or subgroups. For example, in my benchmark, a single zopen call to open a group with 100k subarrays took 13 seconds, while a group with 1m subarrays took 266 seconds. This is a cost we want to avoid when we are only interested in a subset of those subarrays.
functionZGroup(s::T,mode="r",path="";fill_as_missing=false) where T <:AbstractStore
arrays =Dict{String, ZArray}()
groups =Dict{String, ZGroup}()
for d insubdirs(s,path)
dshort =split(d,'/')[end]
m =zopen_noerr(s,mode,path=_concatpath(path,dshort),fill_as_missing=fill_as_missing)
ifisa(m, ZArray)
arrays[dshort] = m
elseifisa(m, ZGroup)
groups[dshort] = m
end
end
attrs =getattrs(s,path)
startswith(path,"/") &&error("Paths should never start with a leading '/'")
ZGroup(s, path, arrays, groups, attrs,mode=="w")
end
This PR introduces lazy group opening, meaning zopen now opens only the target group without recursively opening subarrays or subgroups. Subarrays and subgroups are opened on demand through getindex/setindex!. This change significantly improves performance in the scenarios mentioned above.
Ok, having so many arrays in a Group is indeed problematic when eagerly opening the whole structure recursively. However, there should still be a way for users in a session to interactively explore the arrays and groups contained in a Zarr Group, as I see it there would be no way to achieve this for users given the current PR.
Also, I am a bit concerned about performance implications for the use cases with only a few arrays in the hierarchy. With this PR, this means that for every getindex on a group the metadata would need to be parsed again. I think this should not be a big issue in many cases, but would like to check a few of my downstream applications if they are affected in some way.
Regarding the first point, I can enhance the show method to allow users to view subarrays and subgroups within the current group.
For the second point, I believe the issue won’t be problematic since the user can reuse the object returned by the initial getindex call. While this might require some adjustments to the user’s code, it is manageable on the user’s side. On the other hand, the slowness of zopen that I mentioned here cannot be easily circumvented by the user.
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
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.
Currently,
ZGroupopens a group immediately and recursively, which causes performance issues, especially when the group contains a large number of subarrays or subgroups. For example, in my benchmark, a singlezopencall to open a group with 100k subarrays took 13 seconds, while a group with 1m subarrays took 266 seconds. This is a cost we want to avoid when we are only interested in a subset of those subarrays.Zarr.jl/src/ZGroup.jl
Lines 17 to 33 in e3ccc9d
This PR introduces lazy group opening, meaning
zopennow opens only the target group without recursively opening subarrays or subgroups. Subarrays and subgroups are opened on demand throughgetindex/setindex!. This change significantly improves performance in the scenarios mentioned above.