Registry Mirror
Skip to content

Conversation

@jsignell

@jsignell jsignell commented Mar 6, 2026 •

Copy link
Copy Markdown
Member

Changes the default cache type when passing the path as a string to open_dataset and open_datatree with the h5netcdf engine. This represents a significant improvement when opening optimized hdf5 files. This idea is based off the work that @betolink has been doing in earthaccess (earthaccess-dev/earthaccess#1061)

  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst

Context

This idea came up in conversation with @maxrjones and @hrodmn. It seems to represent a big improvement on the default behavior for certain giant hdf5 stores - in particular NISAR. @hrodmn double checked the performance on this branch and saw significant improvement for NISAR data when opening data from the within the same region:

  • open_datatree on this PR 3.5s, on main: 51.9s
  • open_dataset on this PR 1.3s, on main: 41.5s
  • open_dataarray on this PR 0.9s on main: 48.4s

@kmuehlbauer
kmuehlbauer marked this pull request as ready for review March 7, 2026 07:35
@kmuehlbauer

Copy link
Copy Markdown
Contributor

Sorry Julia, fat fingers, did mark this by accident.

@jsignell
jsignell marked this pull request as draft March 8, 2026 20:28
@jsignell jsignell changed the title Switch to using blockcache with size 8MB by default for h5netcdf Switch to using blockcache with size 4MB by default for h5netcdf Mar 11, 2026
@jsignell
jsignell marked this pull request as ready for review March 11, 2026 21:04
@dcherian

Copy link
Copy Markdown
Contributor

Those are indeed eye-popping improvements!

Where (and how) is this cache maintained? We should be careful here because Xarray maintains an internal cache in CachingFileManager of default size 128. So if each entry is 4MB then that's 0.5GB of storage a user is unaware they are using.

@jsignell

Copy link
Copy Markdown
Member Author

Where (and how) is this cache maintained? We should be careful here because Xarray maintains an internal cache in CachingFileManager of default size 128. So if each entry is 4MB then that's 0.5GB of storage a user is unaware they are using.

Yeah I was worried about that too at first. But by caching here I don't think it means file cache. I think it's more about specifying how large the requests are (ref: https://filesystem-spec.readthedocs.io/en/stable/api.html#readbuffering). It looks like the contents of each block are just stored in the LRUCache.

To be clear there already was "caching" happening by default for this case, it was just "readahead" instead of "blockcache".

@hrodmn

hrodmn commented Mar 12, 2026

Copy link
Copy Markdown

To be clear there already was "caching" happening by default for this case, it was just "readahead" instead of "blockcache".

Indeed. fsspec will use a 50MB read-ahead cache by default. In extreme cases this can result in a lot of extra requests that fetch a lot of extra data. The block cache is more resilient to sub-optimal file layouts where metadata chunks are scattered around a file and not always ordered sequentially.

@dcherian

Copy link
Copy Markdown
Contributor

Yeah I was worried about that too at first.

👏🏾 👏🏾

To be clear there already was "caching" happening by default for this case, it was just "readahead" instead of "blockcache".

Great!

Comment thread xarray/backends/h5netcdf_.py Resolved
# Use blockcache with size 4MB by default
if "cache_type" not in open_kwargs:
open_kwargs["cache_type"] = "blockcache"
if (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@dcherian dcherian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I defer to @kmuehlbauer

@kmuehlbauer kmuehlbauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsignell LGTM, too!

@jsignell
jsignell enabled auto-merge (squash) March 13, 2026 13:32
@jsignell
jsignell disabled auto-merge March 13, 2026 14:01
@jsignell
jsignell merged commit 885e8d1 into pydata:main Mar 13, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make xarray better at reading NISAR data by default

4 participants