Uh oh!
There was an error while loading. Please reload this page.
Implement .to_chunk_cached_arrays() with ChunkCachedArray - #2860
Open
VeckoTheGecko wants to merge 13 commits into
Open
Implement .to_chunk_cached_arrays() with ChunkCachedArray#2860VeckoTheGecko wants to merge 13 commits into
.to_chunk_cached_arrays() with ChunkCachedArray#2860VeckoTheGecko wants to merge 13 commits into
Conversation
Provides an opt-in optimization that wraps dask-backed field data in chunk-level LRU caches via the chunk_cached_array package. Repeated vectorized .isel() calls hit an in-memory cache instead of recomputing dask task graphs, giving large speedups for particle simulations.
Results on ds_2d_left_agrid.zarr with 10k particles: - Plain dask: 85.0s (1x) - Windowed arrays: 16.8s (5.1x) - Cached chunk arrays: 4.9s (17.3x)
Moves the code to a Parcels subpackage (rather than a separate package).
This was a testing-only convenience method, now handled internally by Xarray
instead of `cached_chunk`
erikvansebille
commented
Sep 1, 2026
Member
Thanks for this exciting PR, @VeckoTheGecko! I plan to do some real-world performance testing (also including/comparing #2846 and v3) later this week. Will report back here when I know more! |
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 freeto 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.
Description
Provides an opt-in optimization that wraps dask-backed field data in
chunk-level LRU caches.
vectorized .isel() calls hit an in-memory cache instead of recomputing
dask task graphs, giving large speedups for particle simulations.
This PR adds
ChunkCachedArrayaccording to the approach detailed in #2854 , providing an opt-in optimization wrapping dash-backed field data with (dask)chunk-level LRU caches on the array level. This PR:parcels._chunk_cached_arraywith the implementation of the Array and the needed LRU cache. Note the cache is on the array level with configurable memory limits per array.parcels._chunk_cached_array.wrap_datasetproviding the main entrypoint for Parcels for wrapping Xarray dataset objects.to_chunk_cached_arraystoFieldSetandModelDataclasses.test_backends.py) on a NEMO dataset, asserting that the same results are received regardless of backend.Still needed:
data-generation.py,benchmark_chunk_cache.py,benchmark_chunk_cache.png)Future work:
max_cache_bytesonFieldSet.to_chunk_cached_arraysoperates per variable (i.e., perField). This requires the user to think about how many Fields are in their simulation in order to tune their performance. Down the line, we could tune this to allocate a total cache of (e.g.,) 50% of the system memory (which would allow for other memory overhead of coordinates (not stored in the cache), the Python process, or other user processes). This would require significant refactoring not only on how the chunk cache is handled, but also backends in general.(cc @erikvansebille, @wyatt-fluidnumerics )
Performance
I have some some preliminary profiling with a 20Gb idealised dataset, and found the following performance profile which looks like a promising first step.
I've included
data-generation.pyandbenchmark_chunk_cache.pyhere for testing in case it helps.Its not clear to me the performance with real-world simulations and how that scales (I only have access to my laptop, and found working/debugging on Lorenz quite frustrating with my high latency from travels). Let me know if there's anything I can do to help here @erikvansebille .
Checklist
ChunkCachedArray#2854mainfor normal development,v3-supportfor v3 support)AI Disclosure