Skip to content

Commit

Permalink
Avoid creating default properties unnecessarily (#753)
Browse files Browse the repository at this point in the history
When there are no keyword arguments, just use the global
`DEFAULT_PROPERTIES` rather than creating new `HDF5.Properties` with
default values.

This improves the regression identified in issue #752.
Specifically, the benchmark used in
#752 (comment)
is improved from
```julia
julia> @‌btime fid["mygroup/A"];
  13.872 μs (3 allocations: 96 bytes)
```
on master to
```julia
julia> @‌btime fid["mygroup/A"];
  6.778 μs (1 allocation: 32 bytes)
```
with this commit.
  • Loading branch information
jmert authored Dec 2, 2020
1 parent a77c2c3 commit 11ba575
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,14 +713,14 @@ Base.getindex(x::Attributes, name::AbstractString) = open_attribute(x.parent, na
function Base.getindex(parent::Union{File,Group}, path::AbstractString; pv...)
obj_type = gettype(parent, path)
if obj_type == H5I_DATASET
dapl = create_property(H5P_DATASET_ACCESS; pv...)
dxpl = create_property(H5P_DATASET_XFER; pv...)
dapl = isempty(pv) ? DEFAULT_PROPERTIES : create_property(H5P_DATASET_ACCESS; pv...)
dxpl = isempty(pv) ? DEFAULT_PROPERTIES : create_property(H5P_DATASET_XFER; pv...)
return open_dataset(parent, path, dapl, dxpl)
elseif obj_type == H5I_GROUP
gapl = create_property(H5P_GROUP_ACCESS; pv...)
gapl = isempty(pv) ? DEFAULT_PROPERTIES : create_property(H5P_GROUP_ACCESS; pv...)
return open_group(parent, path, gapl)
else#if obj_type == H5I_DATATYPE # only remaining choice
tapl = create_property(H5P_DATATYPE_ACCESS; pv...)
tapl = isempty(pv) ? DEFAULT_PROPERTIES : create_property(H5P_DATATYPE_ACCESS; pv...)
return open_datatype(parent, path, tapl)
end
end
Expand Down

0 comments on commit 11ba575

Please sign in to comment.