feat: LRU chunk cache for Zarr pixel time series#31
Conversation
|
🚀 Vercel preview deployed Preview URL: https://earth-prints-6sbp0rsg2-anastasiia-s-projects10.vercel.app |
|
/gemini review |
@lazarusA do you have a subscription to use it? |
There was a problem hiding this comment.
Code Review
This pull request introduces a new ZarrChunkReader utility that utilizes a custom LRUCache to optimize Zarr data fetching and prevent redundant network requests, alongside setting up Vitest for unit testing. The review feedback focuses on improving concurrency and performance by caching initialization and fetch promises instead of raw values, adding a delete method to the cache to handle failed requests, enforcing a minimum cache size, and passing pre-opened arrays to avoid redundant open calls.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/gemini summary |
|
/gemini review |
|
Warning Gemini encountered an error creating the summary. You can try again by commenting |
There was a problem hiding this comment.
Code Review
This pull request introduces a chunk-based caching and prefetching mechanism for Zarr time series data. It adds an LRUCache utility, a ZarrChunkReader class to manage prefetching and caching of native Zarr chunks, and updates the EarthMap and MapReadout components to utilize this reader. Additionally, it integrates Vitest for unit testing, adding several test files for the cache and chunk reader utilities. The review feedback highlights two important improvement opportunities in ZarrChunkReader.ts: addressing a potential unhandled promise rejection in the background prefetching logic (prefetchNativeChunks) and removing a redundant .catch() block in loadNativeChunk that duplicates cleanup logic already handled by the .finally() block.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const promise = Promise.all( | ||
| missing.map((timeChunkIdx) => | ||
| this.loadNativeChunk( | ||
| array, | ||
| variable, | ||
| this.nativeCoords(context, timeChunkIdx), | ||
| ), | ||
| ), | ||
| ) | ||
| .then(() => undefined) | ||
| .finally(() => { | ||
| this.prefetchInFlight.delete(prefetchKey); | ||
| }); |
There was a problem hiding this comment.
If any of the chunk loads in Promise.all fail, the promise will reject. Since this prefetch task is executed in the background without being awaited or having a .catch() handler, it will result in an unhandled promise rejection. This can crash the server process in Node.js or pollute the console in the browser.
Adding a .catch() block to silently ignore or log prefetch failures will prevent this issue.
const promise = Promise.all(
missing.map((timeChunkIdx) =>
this.loadNativeChunk(
array,
variable,
this.nativeCoords(context, timeChunkIdx),
),
),
)
.then(() => undefined)
.catch(() => {
// Silently ignore prefetch failures as they will be retried on explicit request
})
.finally(() => {
this.prefetchInFlight.delete(prefetchKey);
});| .catch((error: unknown) => { | ||
| this.chunkLoadsInFlight.delete(key); | ||
| throw error; | ||
| }) | ||
| .finally(() => { | ||
| this.chunkLoadsInFlight.delete(key); | ||
| }); |
There was a problem hiding this comment.
Summary
ZarrChunkReaderthat downloads full spatial Zarr chunks and reuses them for nearby pixel clicks, avoiding repeat network fetches.pixelToChunkKey, slice ranges,extractTimeSeries) and wire the map to the cached reader instead of single-pixel fetches.npm run teston every PR.Details
chunks[2]/chunks[3]).fetchChunkis skipped.