Skip to content

feat(geotiff): route fetchTiles through batched, range-coalescing getTiles - #531

Merged
kylebarron merged 4 commits into
mainfrom
kyle/fetch-tiles-coalesce-applied
May 12, 2026
Merged

kylebarron merged 4 commits into
mainfrom
kyle/fetch-tiles-coalesce-applied

Conversation

@kylebarron

@kylebarron kylebarron commented May 12, 2026 •

Copy link
Copy Markdown
Member

What I am changing

fetchTiles now issues coalesced batched HTTP range requests for tile (and mask) data, instead of Promise.all(xy.map(fetchTile)) — one independent request (or N for band-planar COGs) per tile. This is the follow-up to #530, which vendored getTiles / getMultipleBytes / coalesceRanges but left fetchTiles unchanged. Closes #407.

When the requested coordinates form a contiguous block — e.g. assembling a coarse tile from its finer covering tiles, or (future, #273) a debounce-coalesce middleware in front of deck.gl's per-tile fetches — the byte ranges are contiguous or near-contiguous on disk, so they collapse into far fewer reads (a 2×2 pixel-interleaved COG: 4 → 1; a 2×2 band-planar COG: 12 → 1).

fetchTile's observable behavior is unchanged.

How I did it

  • refactor(geotiff): extract assembleTile from fetchTile — split fetchTile into "fetch the compressed bytes" + "decode/assemble the RasterArray". The decode half (assembleTile) is now shared by fetchTile and fetchTiles; only the I/O half differs.
  • feat(geotiff): batch + coalesce reads in fetchTiles:
    • fetchTiles resolves every requested tile's byte range up front, fetches data and mask concurrently, then decodes per tile via assembleTile, in input order. Early-returns [] for empty input. Stale // TODO: coalesce … removed; JSDoc rewritten.
    • fetchCogBytesMultiple (new): pixel-interleaved → getTiles; band-planar → fetchBandSeparateTileBytesMultiple; a sparse/missing tile throws Tile at (x, y) not found, matching fetchCogBytes.
    • fetchBandSeparateTileBytesMultiple (new): flattens every (tile, band) byte range into a single getMultipleBytes call so coalescing can merge across both bands and neighbouring tiles, then regroups samplesPerPixel results per tile.
    • The mask IFD, if any, is fetched the same batched way (getTiles(self.maskImage, xy, …)).
    • _debug logging still fires (now reporting the post-coalesce ranges).
  • test(geotiff): parity + coalescing tests for batched fetchTiles — see below.
  • Not in this PR (separate follow-ups): exposing coalesce / maxRangeSize knobs through fetchTiles' options; unifying fetchTile onto the batched path; the deck.gl debounce-coalesce middleware (Extend deck.gl tile fetching to enable multi-tile fetches #273).
  • Design notes: dev-docs/specs/2026-05-12-fetch-tiles-coalesce-design.md.

How you can test it

  • pnpm --filter @developmentseed/geotiff exec vitest run tests/fetch.test.ts — 18 passing. New describe("fetchTiles") suite covers:
    • fetchTiles results are byte-for-byte equal to [fetchTile(x,y), …] for pixel-interleaved, band-planar, and masked fixtures;
    • input order preserved for a shuffled request;
    • boundless: false propagates (edge tiles clipped to image bounds);
    • coalescing actually happens — a recording dataSource proxy shows a 2×2 pixel-interleaved COG drop from 4 reads to fewer, and a 2×2×3-band COG from 12 to fewer;
    • empty input → [] with zero reads.
  • pnpm --filter @developmentseed/geotiff typecheck and pnpm biome check packages/geotiff — clean.
  • Note: tests/integration-rasterio.test.ts failures are pre-existing (the .npy reference fixtures under rasterio_generated/fixtures/<name>/ aren't generated locally) and unrelated to this change — they fail identically on main.

Related Issues

🤖 Generated with Claude Code

kylebarron and others added 4 commits May 12, 2026 16:37
Closes the design phase for #407: fetchTiles should issue coalesced
batched range requests via the getTiles/getMultipleBytes/coalesceRanges
helpers vendored in #530, instead of Promise.all over fetchTile.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Splits fetchTile into "fetch compressed bytes" + "decode/assemble the
RasterArray". No behavior change; assembleTile will be shared with the
batched fetchTiles path.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
fetchTiles now resolves every requested tile's byte range up front and
fetches the data through getTiles / getMultipleBytes (range-coalescing),
instead of Promise.all over fetchTile. Both planar configurations:
pixel-interleaved via getTiles; band-planar by flattening every
(tile, band) range into one getMultipleBytes call and regrouping. The
mask IFD, if any, is fetched the same batched way. Decoding is still
per-tile via the shared assembleTile.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Covers fetchTiles vs per-tile fetchTile parity (pixel-interleaved,
band-planar, masked), input-order preservation, boundless: false
propagation, band-planar range coalescing, and empty input.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@kylebarron kylebarron changed the title Kyle/fetch tiles coalesce applied feat(geotiff): route fetchTiles through batched, range-coalescing getTiles May 12, 2026
@github-actions github-actions Bot added the feat label May 12, 2026
@kylebarron
kylebarron marked this pull request as ready for review May 12, 2026 21:06
@kylebarron
kylebarron merged commit 78b18d9 into main May 12, 2026
3 of 4 checks passed
@kylebarron
kylebarron deleted the kyle/fetch-tiles-coalesce-applied branch May 12, 2026 21:13
kylebarron added a commit that referenced this pull request Oct 20, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Bumps `version` to `0.9.0-beta.1` in the root `package.json` and in
every `packages/*/package.json`, ready for a beta release. The publish
workflow sees `beta` in the version and publishes to npm under the
`beta` dist-tag, so `latest` stays on 0.8.1.

`CHANGELOG.md` gets a `v0.9.0-beta.1` section listing the 44 PRs merged
since v0.8.1, plus the two new contributors. This also drops the old
"Unreleased" section: its three entries (#424, #530, #531) already
shipped in v0.7.0.

Once this is merged, tag the merge commit `v0.9.0-beta.1` and push the
tag.

🤖 Written by [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

geotiff: Implement fetch coalescing for GeoTIFF fetchTiles

1 participant