netcdf-c/libhdf5
Greg Sjaardema 1db3d07beb
Proof-of-Concept: Avoid N^2 behavior in NC4_inq_dim
The current library seems to have some behavior which is N^2 in the number of vars in a file.

The `NC4_inq_dim` routine calls down to `nc4_find_dim_len` which iterates through each `var` in the file/group and calls `find_var_dim_max_length` on each var and finds the largest length of the dim on each of those vars. This is done only for unlimited vars.

I have a file with 129 dim and 1630 vars.  The unlimited dimension is of length 41.  In my test program, I am reading data from 4 files which have the same dim and var count and reading every 4th time step (unlimited dimension).  If I run a profile, I see that 98.2% of the program time is in the `nc_get_vara_float` call tree and most of that is in `find_var_dim_max_length` (94.8%).

There are 66,142 calls to `nc_get_vara_float` resulting in 107,307,290 calls to `find_var_dim_max_length` with twice that number of calls to `malloc/free` and calls to 5 HDF5 routines.  All of this, at least in my case, to return the same `41` each time.

The proof of concept patch here will check whether the file is read-only (or no_write) and if so, it will cache the value of the dim length the first time it is calculated.   With this change, my example run is sped up by a factor of 60.  The time for `NC4_inq_dim` and below drops from 97.2% down to 2.7%.

I'm not sure whether this is the correct fix, or if there is some behavior that I am overlooking, but my users would definitely like a 10 second run compared to a 10 minute run... 

This is on current Netcdf master branch.

I will try to attach some valgrind/callgrind profiles.
2020-04-30 11:01:10 -06:00
..
CMakeLists.txt Add support for multiple filters per variable. 2020-02-16 12:59:33 -07:00
H5FDhttp.c typo5 2019-01-02 21:37:31 -07:00
H5FDhttp.h Provide byte-range reading of remote datasets 2019-01-01 18:27:36 -07:00
hdf5attr.c Fix reclamation of the ->format_XXX_info fields 2020-03-29 12:48:59 -06:00
hdf5cache.c improved docs for cache functions, added libhdf5/hdf5cache.c to Doxyfile.in, added benchmark program for cache settings 2019-11-25 16:33:04 -07:00
hdf5create.c whitespace cleanup 2019-08-03 09:04:58 -06:00
hdf5debug.c Fix reclamation of the ->format_XXX_info fields 2020-03-29 12:48:59 -06:00
hdf5debug.h Add support for multiple filters per variable. 2020-02-16 12:59:33 -07:00
hdf5dim.c Proof-of-Concept: Avoid N^2 behavior in NC4_inq_dim 2020-04-30 11:01:10 -06:00
hdf5dispatch.c Fix conflicts with master 2020-02-27 14:06:45 -07:00
hdf5file.c Fix reclamation of the ->format_XXX_info fields 2020-03-29 12:48:59 -06:00
hdf5filter.c stop setting contiguous field in hdf5filter.c 2020-03-08 07:18:11 -06:00
hdf5grp.c cleanup of whitespace in HDF5 directory 2019-02-19 05:18:02 -07:00
hdf5internal.c Fix reclamation of the ->format_XXX_info fields 2020-03-29 12:48:59 -06:00
hdf5open.c Merge remote-tracking branch 'upstream/master' 2020-04-23 15:36:14 -05:00
hdf5type.c Add support for multiple filters per variable. 2020-02-16 12:59:33 -07:00
hdf5var.c Fix reclamation of the ->format_XXX_info fields 2020-03-29 12:48:59 -06:00
Makefile.am Add support for multiple filters per variable. 2020-02-16 12:59:33 -07:00
nc4hdf.c Merge remote-tracking branch 'upstream/master' 2020-04-23 15:36:14 -05:00
nc4info.c Make the dap4 code resistant to various server errors. 2020-01-08 15:18:31 -07:00
nc4mem.c re: github issues 2018-10-30 20:48:12 -06:00
nc4memcb.c Spelling fixes 2019-09-18 08:03:01 -06:00