Skip to content

feat(geotiff)!: read COGs through the range reader - #807

Merged
kylebarron merged 11 commits into
mainfrom
kyle/range-reader-geotiff
Oct 28, 2026
Merged

kylebarron merged 11 commits into
mainfrom
kyle/range-reader-geotiff

Conversation

@kylebarron

@kylebarron kylebarron commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code), not by @kylebarron.

Stage 2 of the range reader (stacked on #806): GeoTIFF.fromUrl reads through a RangeReader, so the header reads cogeotiff makes (IFDs, then one offset-table entry per tile) and the tile reads are merged into few streamed range requests, each tile resolves as its bytes arrive, and everything received is cached. GeoTIFF.open, fetchTile, fetchTiles and the deck.gl layers are unchanged; stage 3 (next PR) makes the layers share one reader by default.

Design: dev-docs/specs/2026-10-26-range-reader-design.md, section "@developmentseed/geotiff on the reader".

Changes

  • RangeReaderSource: a chunkd Source over one reader, URL, purpose, limiter and request init. fromUrl builds two over one reader, purpose metadata for cogeotiff's Tiff and purpose data for tile bytes, so the two are merged and budgeted separately (and a tile that arrived inside the first metadata block is served from it, or attaches to it while it streams). Its size is seeded infinite and never updated, the SourceError: Request outside of bounds #524 guard.
  • GeoTIFFFromUrlOptions: new reader (share one across files to share its cache and batching window; omitted, a private reader with default options) and requestInit (headers, credentials, mode for every request of the file; files read with different inits never share a request or a cached byte). Breaking: chunkSize and cacheSize are removed; they are RangeReader options now (minMetadataReadBytes, cache.metadataBytes). concurrencyLimiter and getPriority are unchanged.
  • Removed: the chunkd SourceChunk + LRUCacheMiddleware + LimiterMiddleware stack, cache.ts, limiter.ts, coalesce.ts and their tests. @chunkd/source-http is no longer a dependency; @chunkd/middleware moves to devDependencies (one test still composes a chunkd source for GeoTIFF.open).
  • getMultipleBytes issues one read per range in one task instead of merging with its own 1 MiB gap underneath the reader's over-fetch cap; the reader merges.
  • Tests: a fixture server that answers like S3 behind CORS (206 with Content-Length only, streamed bodies, held and failed requests) replaces the SourceHttp.fetch stubs. The header-read and limiter tests keep every behavioural guarantee (one request per header block shared by the tiles that need it, one tile's abort never failing another, one limiter slot per request and none for a cache hit, a queued read dropped on abort before any fetch); the fetchTiles grid tests now assert the reader's request count end to end and pixel-equal tiles. The Vermont example gets its own reader with a 64 MiB metadata budget in place of cacheSize.

After Kyle's review of #806 (2026-10-27)

  • Follows the rename to the metadata purpose and the narrower ReadRange (8c7b175).
  • RangeReaderSource remembers the validator of its first result and throws an ETag conflict error when a later one differs, as chunkd's SourceHttp did and this PR had silently dropped: a COG replaced in place mid-session now fails loudly instead of decoding garbage from stale offsets, and a reopen over the same reader works because the reader keeps only the new version (70adf3c).

🤖 Written by Claude Code

🤖 Generated with Claude Code

@kylebarron
kylebarron added this pull request to stack #808 October 27, 2026 16:09
@kylebarron kylebarron changed the title kyle/range reader geotiff feat(geotiff)!: read COGs through the range reader Oct 27, 2026
@kylebarron
kylebarron force-pushed the kyle/range-reader-geotiff branch from 42fc4d4 to 5e51311 Compare October 27, 2026 21:49
@kylebarron
kylebarron force-pushed the kyle/range-reader-geotiff branch from 5e51311 to 6c8863f Compare October 27, 2026 21:58
@kylebarron
kylebarron force-pushed the kyle/range-reader-geotiff branch from 6c8863f to f3aaf18 Compare October 28, 2026 00:32
Base automatically changed from kyle/range-reader to main October 28, 2026 00:36
kylebarron added a commit that referenced this pull request Oct 28, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Adds `@developmentseed/range-reader`, a new workspace package that turns
the byte-range reads a client issues in one task into few streamed HTTP
range requests, resolves each read the moment its bytes arrive, cancels
a request as soon as no read wants what is left of it, and keeps every
received span in a byte cache. It is stage 1 of three: nothing reads
through it yet. Stage 2 (next PR in this stack) puts `GeoTIFF.fromUrl`
on it; stage 3 makes the deck.gl COG layers share one reader by default.

Design: `dev-docs/specs/2026-10-26-range-reader-design.md` (committed
here). Background: #273, #747, #762, #690, #524; the usgs-topo prototype
(kylebarron/usgs-topo#23) that measured 226 requests / 4.19 s down to 30
/ 0.79 s for a zoom-12 view of 128 px tiles, which this package
generalises and improves on by streaming.

## What is in the package

- `RangeReader.read(file, range, { purpose, signal, limiter, getPriority
})`: queues absolute reads until the end of the task, groups them by
file identity (URL plus a canonical request-init signature, so different
credentials never share bytes) and purpose (`metadata` or `data`; `data`
when omitted), widens small metadata reads to aligned 64 KiB blocks that
are read to their end, merges them with the usgs-topo rule plus two caps
(`maxOverfetchBytes`, 1 MiB; `maxRequestBytes`, 16 MiB; `maxGap:
"median"`), and runs one `RangeStream` per merged range. Before
queueing, a read is served from the cache, or attached to a request
already in flight, of either purpose, or resolved empty past a known
object size. Suffix and whole-object reads go out at once, unmerged.
`reader.stats` counts requests, bytes, over-fetch, cache hits, attaches
and validator changes for the measurement gate.
- `RangeStream`: one range request, body read as a stream into a
preallocated buffer; each member read resolves with a view the moment
its last byte lands; a member whose signal aborts rejects at once and
the stream runs on for the others, and is cancelled, keeping what
arrived, when the last live member leaves (by abort, or by a resolve
once others have left). Handles 206, 200 to a ranged request (consumed
as the whole object when its `Content-Length` is small enough, else
rejected), 404 (a typed not-found outcome, since a missing Zarr chunk is
data), other statuses, a body that ends before the range (end of object,
told apart from a truncated transfer by `Content-Length`), a body that
runs past the range, and body errors from a real `fetch` on abort or a
dropped connection. One limiter slot per request, with the best priority
among live members.
- `MemoryByteCache` (the default `ByteCache`): contiguous spans per
file, served by containment as views, one LRU budget per purpose (32 MiB
metadata, 64 MiB data) so tile churn never evicts the offset tables
every later read depends on; a read of either purpose is served from any
span that contains it. `ByteCache` is an interface (`get`, `put`,
optional `byteSize` and `delete`) so a disk-backed cache (OPFS) can be
supplied later.
- The per-origin limiter (`Semaphore`, `PerOriginSemaphore`,
`ConcurrencyLimiter`, `Priority`) moves here from
`@developmentseed/geotiff`, which re-exports the same names and keeps
its chunkd `LimiterMiddleware`. No other change to geotiff's API.

88 tests drive fake responses chunk by chunk (the fake errors the body
on abort, like a real `fetch`). A fresh whole-branch review found two
confirmed bugs (body errors rejected `run()` and hung reads; cancelled
prefixes pinned their whole preallocated buffer) and two rule gaps, all
fixed with tests in `a28d18d1`.

Registered on the docs site (`range-reader`); the API pages are
generated at build time like every other package's.

## After Kyle's review (2026-10-27)

- Two bugs found while checking the review, both only visible with a
body that arrives in more than one chunk: a widened metadata block was
cancelled right after its small read resolved, so only the first chunk
was cached and the block was requested again (live during the #809
measurements); and a data read inside a metadata block still streaming
went out as its own request instead of attaching. Fixed in 79eebe2 with
two-chunk tests; a keep member that offers no priority no longer sets
the request's (5fc6c7b).
- The structural purpose is `metadata`, not `header`: the same class of
bytes is a sharded Zarr shard's index and a PMTiles directory. Options
follow (`minMetadataReadBytes`, `cache.metadataBytes`); `purpose` is
optional and defaults to `data` (355b531).
- `ReadRange` no longer includes `undefined`; `FileIdentity.key` is a
branded `FileKey` only `fileIdentity()` makes; the key's parts are
separated by a space, which a serialized URL never contains; the
`fileIdentity` docstring says why the identity exists: one merged
request carries one set of headers (d48caa6).
- Validators: chunkd's `SourceHttp` failed reads whose ETag changed and
the stack had dropped that guard. The reader keeps each file's `ETag`
(or `Last-Modified`) from its latest response, purges the file's cached
spans and forgets its size when it changes, and reports the validator on
every result, cache hits included; `ByteCache.delete` is the purge hook.
The reader never sends `If-Match` (CORS preflight); icechunk's own
`If-Match` passes through the init (5691502). The geotiff adapter in
#807 does the per-instance check.
- README: why merging pays (six HTTP/1.1 connections per host,
per-request latency and billing, interleaving over HTTP/2), sharded Zarr
as a client, the metadata definition (67aa356).

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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
@kylebarron
kylebarron force-pushed the kyle/range-reader-geotiff branch 2 times, most recently from 94e6441 to ae051a3 Compare October 28, 2026 00:38
Comment on lines +120 to +121
reads every COG through it (`GeoTIFF.fromUrl`). Stage 3 makes the deck.gl
COG layers share one reader by default.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

so this means there's a single app-wide cache, for all layers? I guess this is good to be able to keep the total cache below a certain size. I guess it would be cool if even Zarr layers could hook into the same app-wide image chunk cache

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

Yes. Stage 3 (#809) gives deck.gl-geotiff one module-level DEFAULT_RANGE_READER, so every COGSource, MultiCOGSource and MosaicLayer on a page shares one byte cache, 32 MiB of metadata plus 64 MiB of data by default, and one batching window: a tile fetched for one layer is served from memory to another, and the page never holds more than those budgets in compressed bytes. Zarr joining it is the plan: the Zarr adapter is a fetch-shaped store for zarrita and icechunk over the same default reader, so chunk bytes land in the same cache under the same budgets, with shard indexes counted as metadata. One distinction: this cache holds compressed bytes as they came off the wire; a decoded-chunk cache shared across layers, CPU or GPU, is the chunk-manager design, not this one.

🤖 Written by Claude Code

Comment on lines +347 to +349
reader = new RangeReader({
cache: { metadataBytes: 8 * 1024 * 1024, dataBytes: 8 * 1024 * 1024 },
}),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So the idea is that a RangeReader will be shared across the entire app while a RangeReaderSource is a specific view/worker on the RangeReader?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

Right. A RangeReader is the long-lived, shared thing: the byte cache, the per-task merge queue, the in-flight streams, the learned object sizes and validators. The source is a cheap per-file, per-purpose handle in chunkd's Source shape, which is what cogeotiff's Tiff calls: it holds the file identity (URL plus init), the purpose, the limiter and priority, and the first validator it saw. fromUrl makes two per file over one reader, metadata and data; a page with a thousand mosaic sheets has two thousand handles and one reader. Not a worker: everything stays on the main thread, and the only work in the handle is copying a result into a fresh ArrayBuffer.

🤖 Written by Claude Code

reader = new RangeReader({
cache: { metadataBytes: 8 * 1024 * 1024, dataBytes: 8 * 1024 * 1024 },
}),
requestInit,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is new? So this will support our authentication issues, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

New in this PR, yes: headers, credentials and mode sent with every request for the file, and in #809 it reaches COGSource.open, MultiCOGSource.open and the MosaicLayer prop. It covers a bearer token, a cookie session (credentials: "include") and custom headers. Two caveats: the init is fixed for the file's lifetime, so a token that expires mid-session needs a reopen; and files read with different inits never share a request or a cached byte, so a refreshed token on the same URL refetches that file's metadata blocks. For per-request signing, Planetary Computer SAS tokens for instance, the dynamic path is the reader's fetch option, which can sign each request as it goes out while the identity stays the plain URL, so the cache survives rotation.

🤖 Written by Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I need to read through this file closer tomorrow

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

For when you do: the change in this file is small. getMultipleBytes used to merge its ranges itself with a fixed 1 MiB gap, six at a time, underneath the reader's own over-fetch cap; it now issues one read per range in one task and lets the reader merge, and it checks for a short read. fetchTile and fetchTiles are otherwise unchanged, and the band-separate grid test now asserts the reader's request count end to end.

🤖 Written by Claude Code

Comment thread packages/geotiff/src/reader-source.ts Resolved
kylebarron added a commit that referenced this pull request Oct 28, 2026
…es, 1 MiB default (#815)

> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Three changes from the timing benchmark of the stack (#807, #809), each
measured; the before-and-after tables are in #809's description.

- **Adjacent reads respect the request cap.** `mergeReads` treated a
read that starts exactly where the current range ends like an
overlapping one and joined it unconditionally. The tiles of a COG row
are contiguous, so they merged without any bound and `maxRequestBytes`
never applied: in `cog-basic`, ten 2.4 MB tiles became one 24 MB request
and a viewport of big tiles ran on two or three streams, which cannot
fill a fast link that ten parallel requests fill (0.6x of unmerged on an
emulated 200 Mbit/s, 80 ms link). Only a read that starts before the
range's end, a true overlap, joins past the cap now.
- **Merged ranges launch round-robin across files.** A limiter serves
streams in launch order and COG tile reads carry no priority, so
launching every range of one file before the next file's meant a
MultiCOG tile, which needs one range of each band file, could not
complete until the last file's streams started: sentinel-2's first tile
arrived 2.5 s after a jump at every cap, against 0.5 s unmerged; it is
0.85 s with this change, and the view completes 1.2x to 1.4x faster than
unmerged.
- **Default `maxRequestBytes` is 1 MiB** (the third commit set 4 MiB;
the fourth corrects it after the final pass), from a sweep of 1 to 16
MiB under three link conditions: merging pays when tiles are small
against the link's latency, and about 1 MiB is where it stops paying. A
128 px topo sheet's 99 reads still merge to 9 requests and load 2x to 4x
faster; 460 KB NAIP tiles merge in pairs at parity or better, where 2 to
4 MiB cost 20% to 30% on a home link; 2.4 MB tiles go alone, at parity.
A larger cap buys up to 20% on a high-latency link for mid-size tiles at
the cost of the first tile; an adaptive cap derived from the selection's
size, so a view always yields enough streams to fill the link, is the
follow-up.

Independent of #807 and #809 textually; merging it first and rebasing
the stack is the simplest order.

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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
kylebarron and others added 10 commits October 28, 2026 12:39
`RangeReaderSource` maps chunkd's `fetch(offset, length)` onto
`RangeReader.read` for one file, purpose, limiter and request init, so
cogeotiff's header reads and our tile reads can share the reader's
merging, streaming and cache. Its size stays infinite (#524). A fixture
server that answers like S3 behind CORS backs the tests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
`GeoTIFF.fromUrl` now builds two `RangeReaderSource`s over one
`RangeReader`, purpose `header` for cogeotiff's `Tiff` and purpose `data`
for tile bytes, so header and tile reads are merged into few streamed
range requests and cached. New options `reader` (share one across files)
and `requestInit` (headers, credentials, mode for every request). The
`chunkSize` and `cacheSize` options are gone: they are reader options now
(`minHeaderReadBytes`, `cache.headerBytes`). The chunkd chunking, LRU and
limiter middlewares are removed with them; `@chunkd/source-http` is no
longer a dependency.

The header-read and limiter tests are ported to a fixture server that
answers like S3 behind CORS, and keep every behavioural guarantee: one
request per header block shared by the tiles that need it, one tile's
abort never failing another, one limiter slot per request and none for a
cache hit, a queued read dropped on abort before any fetch.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
`getMultipleBytes` issued its ranges through a local coalescer with its
own 1 MiB gap and 16 MiB cap, which would have merged underneath the
reader's over-fetch cap. It now issues one read per range in one task and
lets the data source merge them; `coalesce.ts` is gone with its options.
The `fetchTiles` grid test now checks the reader's request count end to
end and that the tiles equal per-tile reads.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…header budget

`GeoTIFF.fromUrl` no longer takes `cacheSize`; the header budget is a
`RangeReader` option now.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Findings of the whole-branch review:

- A bare `fromUrl` gave every file a private reader with the default
  96 MiB of budgets, so opening many files this way could retain that
  many times over. The private reader now has 8 MiB header and 8 MiB
  data budgets; share a reader to pool them.
- The README's "bring your own source" section imported chunkd packages
  this branch removed from the dependencies; it now shows a local-file
  stack and sends HTTP readers to `fromUrl`, and says that without a
  limiter every merged request goes out at once.
- Comments in `fetch.ts` still described the data source as uncached and
  the batch paths as coalescing locally.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The sentence still said tile reads bypass the cache and go to the raw
HTTP source.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The reader's structural purpose is now "metadata", with
`minMetadataReadBytes` and `cache.metadataBytes`, and `ReadRange` no
longer includes the whole-object case; the header source, the fallback
reader's budgets, the adapter's range type, the tests, the README and
the Vermont example follow. The Vermont example's NDVI colormap
docstring sits above its constant again.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…kd did

chunkd's SourceHttp remembered a file's ETag and failed later reads
whose ETag differed; replacing it dropped that guard, so a COG replaced
in place mid-session decoded garbage from stale offsets. The reader now
reports each result's validator; `RangeReaderSource` remembers the first
one per instance and throws an `ETag conflict` error on a change. A
stale `GeoTIFF` fails loudly on every read, including cache hits, since
the reader keeps only the new version; a fresh one over the same reader
works. The fixture server can send an ETag and change it between
requests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…rSource

"Source" now means a dataset in this repo (COGSource, MultiCOGSource,
RasterSource), while cogeotiff's byte-range interface is also called
Source. The adapter over the range reader is now `ByteSource`, with
chunkd's interface imported as `ChunkdSource`, and its docstring says
which of the two it is. Internal to the package; no export changes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kylebarron
kylebarron force-pushed the kyle/range-reader-geotiff branch from 6fffa38 to 066da2f Compare October 28, 2026 16:40
Comment thread packages/geotiff/src/byte-source.ts Resolved
Comment thread packages/geotiff/src/byte-source.ts Outdated
Comment on lines +35 to +40
* `metadata.size` is seeded infinite and never updated: cogeotiff clamps a
* read to the size it knows, and in a browser a range response often reveals
* only the range's own `Content-Length`, which once got recorded as the file
* size and rejected every later read past it
* (https://github.com/developmentseed/deck.gl-raster/issues/524). The reader
* handles the end of the object on its own.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

isn't it problematic here that we're tailoring the generic byte source reader specifically to cogeotiff? I thought the cogeotiff bug referenced above was patched upstream?

@kylebarron kylebarron Oct 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

Checked, and the seed is gone in 28220e7. #524 was a chunkd bug, not a cogeotiff one: SourceHttp recorded a range response's Content-Length as the file size when CORS hid Content-Range, and SourceChunk's bounds check then rejected every read past it. We worked around it in #527 by turning the check off; it was never patched upstream, chunkd 11.4.1 still does it. This PR removes both SourceHttp and SourceChunk, so nothing records a size any more, and cogeotiff's own getMaxLength reads the requested length when a source has no size, which makes the infinity seed unnecessary. metadata now stays undefined. What is left in ByteSource is only chunkd's interface, which is cogeotiff's byte interface by definition, and the validator check that chunkd's SourceHttp also did.

🤖 Written by Claude Code

Docstrings state what each thing is and the rule a caller needs; the
history behind them is in the PR. `ByteSource` no longer seeds
`metadata.size` with infinity: cogeotiff reads the requested length when
a source has no size, and the chunkd code that recorded a wrong size is
gone from this package.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kylebarron
kylebarron merged commit 3b550b1 into main Oct 28, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/range-reader-geotiff branch October 28, 2026 18:38
kylebarron added a commit that referenced this pull request Oct 28, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Stage 3 of the range reader (stacked on #807): the deck.gl COG layers
share one `RangeReader` by default, hand a whole selection to it in one
task, and abort a tile's load the moment the tile leaves the view, so
coalesced, streamed, cached range requests are the default path for
every COG layer, with no change to deck.gl.

Design: `dev-docs/specs/2026-10-26-range-reader-design.md`, section
"deck.gl-geotiff and deck.gl-raster". Closes #273 (no `getMultiTiles`
needed: the batching happens below `getTileData`), closes #747 (the gap
rule and caps are reader options; defaults below), closes #762 (received
bytes are cached, a pan back refetches nothing).

## Changes

- `DEFAULT_RANGE_READER` in deck.gl-geotiff, next to
`DEFAULT_CONCURRENCY_LIMITER`: every `COGLayer`, `MultiCOGLayer` and
`MosaicLayer` on a page shares one byte cache and one batching window.
`COGSource.open`, `MultiCOGSource.open` and `MosaicLayer` take `reader`
and `requestInit` (headers, credentials, mode for data behind
authentication) and forward them to `GeoTIFF.fromUrl`; the mosaic passes
them to `getSource` like the limiter.
- `COGLayer` and `MultiCOGLayer` default to `maxRequests: 256` and
`debounceTime: 50`: deck.gl's six-at-a-time throttle would starve the
reader, which merges a selection's reads and is capped by the per-origin
limiter instead; the debounce lets a pan settle before anything is
requested. `RasterTileLayer` and `MosaicLayer` keep deck.gl's defaults
(#562).
- `RasterTileset2D` gains an internal `abortUnwantedLoads` option: after
every update, a loading tile that is neither selected nor visible is
aborted. deck.gl does that only while more than `maxRequests` loads are
in flight; without the rule a streamed request would run on for tiles
that left the view. `RasterTileLayer` exposes it as a protected hook,
off by default; the two COG layers turn it on. `ZarrLayer` is untouched
until its own reader adapter lands, because zarrita's coalescer fails
every read of a merged request when one of them aborts.
- Docs: a "Requests, caching and authentication" section in the
deck.gl-geotiff README.

## Measurements

Same machine, same hour, headed Chrome 156 through the CDP harness in
`dev-docs/perf-harness`, two repeats, counting only the S3 host. Before
is the stage 1 tip (behaviour identical to `main`), after is this
branch. Settled screenshots are pixel-identical (ImageMagick `compare
-metric AE` = 0) for every scenario. The review of this PR found two
things fixed in `87b49a85`: a loading tile that deck.gl evicted inside
its own update kept its stream alive (now aborted through the tileset's
`onTileUnload`), and the README showed `reader`/`requestInit` as
`COGLayer` props, which do not exist (open the source yourself;
`MosaicLayer` has the props).

| Example | Scenario | Before (requests / MB) | After (requests / MB) |
|---|---|---|---|
| cog-basic (Sentinel-2 TCI, 1024 px tiles of ~2.4 MB) | load | 14 / 4.4
| **3 / 4.3** |
| cog-basic | zoom +3, cold cache | 28 / 22.8, 18 cancelled | **9-10 /
22.8, 6-7 cancelled** |
| cog-basic | zoom +3, warm | 28-29 / 22.8-23.5 | **10 / 22.8** |
| cog-basic | pan 1 viewport | 8 / 19.0 | 8 / 19.0 |
| cog-basic | ten fast pans (1 viewport each, 20 frames) after the zoom
| 8 / 19.0, 0 cancelled | 5 / 19.0, 0 cancelled |
| cog-basic | pan 3 viewports away, then back | away: 11 / 4.8 (5
cancelled); back: 5 / 4.6-9.6 | away: 11 started, all cancelled before a
byte, 0 MB; back: same, 0 MB |
| sentinel-2 (MultiCOGLayer, one scene's band files) | load | 36-42 /
8.5-10.5 | **9 / 10.3** |
| sentinel-2 | zoom +2 | 114-117 / 36.3-37.4, 12 cancelled | **23 /
35.2, 8 cancelled** |
| usgs-topo (one HTMC sheet, 128 px tiles) | load | 151-154 | **3-5** |
| usgs-topo | pan 0.5 viewport | 0 | 0 |

The single pan on cog-basic brings in one column of new tiles, which are
not adjacent in file order, so nothing merges there and nothing is
worse; the ten fast pans fetch the same bytes with fewer requests, and
the pan-away-and-back is the #762 case: before, the way back refetched
five tiles that had been evicted; after, every request started mid-pan
was cancelled before a byte arrived and the view on return was served
from cache. Settle times were too noisy on this connection to read (the
2 MB tiles are bandwidth-bound; cold zoom 2.8 / 3.2 s before against 2.7
/ 5.2 s after, and the reverse spread on the warm run; sentinel-2 zoom
6.3 / 6.6 s before, 6.0 / 8.6 s after).

Not run, left for the review: `naip-mosaic`, `vermont-cog-comparison`,
the usgs-topo mosaic app linked against this build, the centre-tile
timing, and the knob sweeps (`maxGap`, `maxOverfetchBytes`,
`debounceTime`, `cacheMode`). The defaults are the spec's
first-implementation values: `maxGap: "median"`, `maxOverfetchBytes` 1
MiB, `maxRequestBytes` 16 MiB, `minMetadataReadBytes` 64 KiB, cache 32
MiB metadata + 64 MiB data shared page-wide. To rerun:
`dev-docs/perf-research-2026-10.md`, "How to re-run" (the harness needs
the `window.__overlay` hook from its instrumentation patch applied to
`examples/_shared`).

## After Kyle's review of #806 (2026-10-27)

The numbers above were measured before the widened-block fix in #806 (a
metadata block was cancelled after its first chunk and requested again),
so the metadata-side request counts, the usgs-topo sheet load in
particular, should be lower now; the gate still needs the rerun listed
above. The README follows the `metadata` budget name.

## Timing (2026-10-28, with #815)

Does it make things faster, and how much? Measured on the same machine
with the CDP harness, cold cache, headed Chrome 156, as instant camera
jumps so the numbers are request timing rather than animation: *first
tile* is the time from the jump until the first newly selected tile is
loaded, *all loaded* until every root layer reports loaded, both sampled
per animation frame from deck's tile state, no idle floor. *Before* is
`main` after #806 (chunkd path, deck.gl's six at a time), five repeats;
*after* is this stack plus #815 with its 1 MiB default, three repeats.
Page load is from navigation to all tiles loaded and includes the app's
own bootstrap; it varies several-fold run to run in both builds
(sentinel-2's ranges 1 to 9 s), so read the jump rows, not the page-load
rows. Medians.

**native (home link, ~45 Mbit/s, low RTT)**

| Example | Step | First tile before -> after (ms) | All loaded before
-> after (ms) | Speedup | Requests before -> after | MB |
|---|---|---|---|---|---|---|
| usgs-topo | page load | 510 -> 752 | 1988 -> 1749 | **1.14x** | **89
-> 35** | 0.3 |
| usgs-topo | zoom +2 (jump) | 136 -> 197 | 1943 -> 579 | **3.36x** |
**99 -> 9** | 0.6 |
| usgs-topo | pan 1 viewport (jump) | 132 -> 186 | 721 -> 299 |
**2.41x** | **32 -> 8** | 0.1 |
| naip-mosaic | page load | **146 -> 573** | 8484 -> 9112 | 0.93x | 257
-> 257 | 47.3 |
| naip-mosaic | zoom +2 (jump) | **185 -> 624** | 2993 -> 3508 |
**0.85x** | 50 -> 33 | 22.0 |
| naip-mosaic | pan 1 viewport (jump) | 19 -> 17 | 2376 -> 2737 |
**0.87x** | 30 -> 20 | 10.8 |
| sentinel-2 | page load | 691 -> 1022 | 1487 -> 3408 | **0.44x** | 75
-> 51 | 11.2 |
| sentinel-2 | zoom +2 (jump) | 489 -> 532 | 5738 -> 5025 | **1.14x** |
99 -> 50 | 36.9 |
| cog-basic | page load | - -> - | 618 -> 660 | 0.94x | 47 -> 36 | 4.7 |
| cog-basic | zoom +3 (jump) | 747 -> 1015 | 4088 -> 4162 | 0.98x | 10
-> 10 | 23.9 |
| cog-basic | pan 1 viewport (jump) | 1154 -> 920 | 3318 -> 3521 | 0.94x
| 8 -> 8 | 20.0 |

**emulated 200 Mbit/s, 80 ms RTT**

| Example | Step | First tile before -> after (ms) | All loaded before
-> after (ms) | Speedup | Requests before -> after | MB |
|---|---|---|---|---|---|---|
| usgs-topo | page load | 621 -> 825 | 2434 -> 1840 | **1.32x** | **92
-> 35** | 0.4 |
| usgs-topo | zoom +2 (jump) | 146 -> 181 | 2164 -> 559 | **3.87x** |
**99 -> 9** | 0.6 |
| usgs-topo | pan 1 viewport (jump) | 142 -> 224 | 741 -> 340 |
**2.18x** | **32 -> 8** | 0.1 |
| naip-mosaic | page load | 232 -> 309 | 9163 -> 9258 | 0.99x | 257 ->
257 | 47.3 |
| naip-mosaic | zoom +2 (jump) | **188 -> 551** | 3165 -> 2985 | 1.06x |
50 -> 33 | 22.0 |
| naip-mosaic | pan 1 viewport (jump) | 16 -> 19 | 1965 -> 2403 |
**0.82x** | 30 -> 20 | 10.8 |
| sentinel-2 | page load | 768 -> 969 | 1712 -> 1663 | 1.03x | 75 -> 51
| 11.2 |
| sentinel-2 | zoom +2 (jump) | 521 -> 635 | 5498 -> 4446 | **1.24x** |
99 -> 50 | 36.9 |
| cog-basic | page load | - -> - | 798 -> 829 | 0.96x | 47 -> 36 | 4.7 |
| cog-basic | zoom +3 (jump) | 1076 -> 1278 | 3258 -> 3094 | 1.05x | 10
-> 10 | 23.9 |
| cog-basic | pan 1 viewport (jump) | 1031 -> 1224 | 2905 -> 2948 |
0.99x | 8 -> 8 | 20.0 |

**emulated 10 Mbit/s, 150 ms RTT**

| Example | Step | First tile before -> after (ms) | All loaded before
-> after (ms) | Speedup | Requests before -> after | MB |
|---|---|---|---|---|---|---|
| usgs-topo | page load | 837 -> 1089 | 3973 -> 3410 | **1.17x** | **82
-> 35** | 0.3 |
| usgs-topo | zoom +2 (jump) | 234 -> 248 | 3067 -> 928 | **3.30x** |
**99 -> 9** | 0.6 |
| usgs-topo | pan 1 viewport (jump) | 199 -> 278 | 1088 -> 526 |
**2.07x** | **32 -> 8** | 0.1 |
| naip-mosaic | page load | 751 -> 470 | 40406 -> 40332 | 1.00x | 257 ->
257 | 47.3 |
| naip-mosaic | zoom +2 (jump) | **729 -> 4275** | 16904 -> 17449 |
0.97x | 50 -> 33 | 22.0 |
| naip-mosaic | pan 1 viewport (jump) | 17 -> 16 | 8918 -> 9107 | 0.98x
| 30 -> 20 | 10.8 |
| sentinel-2 | page load | 3791 -> 3311 | 10604 -> 10351 | 1.02x | 71 ->
51 | 9.3 |
| sentinel-2 | zoom +2 (jump) | 1849 -> 2192 | 29885 -> 29831 | 1.00x |
99 -> 50 | 36.9 |
| cog-basic | page load | - -> - | 2049 -> 2037 | 1.01x | 47 -> 36 | 3.9
|
| cog-basic | zoom +3 (jump) | 11133 -> 11147 | 19367 -> 19480 | 0.99x |
10 -> 10 | 23.9 |
| cog-basic | pan 1 viewport (jump) | 11497 -> 11188 | 16274 -> 16320 |
1.00x | 8 -> 8 | 20.0 |

Reading it:

- **Small tiles win, everywhere.** usgs-topo's 128 px tiles: a zoom
completes 3.4x to 3.9x faster and a pan 2.1x to 2.4x faster in every
link condition; page load 1.1x to 1.3x. The first tile is 50 to 80 ms
later, which is the new 50 ms debounce.
- **Multi-file tiles win on fast links.** sentinel-2 (MultiCOGLayer, ten
scenes): 1.14x native, 1.24x on the fast link, equal on the slow link
where bytes are all that matters; the first tile is back at the unmerged
0.5 s after #815's round-robin launch, where the unbounded merge had it
at 2.5 s.
- **Big single tiles are at parity.** cog-basic's 2.4 MB tiles do not
merge at a 1 MiB cap; the view is the same requests as before and loads
in the same time (0.94x to 1.05x). What this stack adds there is the
cache and the cancellation, not speed: the pan-away-and-back case
fetches nothing on the way back.
- **A mosaic of mid-size tiles is the one mixed case.** naip-mosaic's
460 KB tiles merge in pairs (50 to 33 requests); a zoom on the home link
is 0.85x and a pan 0.83x, the fast link 1.13x and 0.92x, five
interleaved repeats each. The request timelines say why: no metadata
requests during the zoom (offsets are cached at load), five of six
streams busy on average in both builds, the same 9 Mbit/s per stream in
both, so this link only reaches its 45 to 50 Mbit/s with all six streams
running, and this bucket is in Azure EU West at 120 ms to first byte.
Merged units of about 780 KB against 460 KB single tiles leave a longer
tail where fewer than six streams are busy; the latency saved by 17
fewer requests is real but smaller than that tail on this link, and the
arithmetic flips on the fast link. Two launch orders were tried against
it: largest-first brings the zoom to parity (1.00x home, 1.21x fast) but
delays sentinel-2's first tile from 0.53 s to 1.27 s, and a
first-run-then-largest hybrid keeps the first tile but loses the naip
win; neither is in #815, both are on
`experiment/range-reader-launch-order`. The remaining fix is an adaptive
cap derived from the selection's size, so a small selection such as a
pan yields enough units to keep six streams busy; that is the follow-up.
- **Two bugs the benchmark found are in #815**, which this stack should
land after: contiguous tiles merged without any bound because an
adjacent read counted as overlapping, which is why the first pass of
this benchmark showed big tiles at 0.6x on the fast link; and merged
ranges launched file by file, which held every MultiCOG tile until the
last band file's streams started.

Not measured: your usgs-topo mosaic app against this build, and HTTP/2
hosts (all four examples read from S3 or Azure Blob, which are
HTTP/1.1).

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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
kylebarron added a commit that referenced this pull request Oct 30, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

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

`CHANGELOG.md` gets a `v0.10.0-beta.1` section listing the 19 PRs merged
since v0.9.0.

## Publish `@developmentseed/range-reader` by hand before tagging

`@developmentseed/range-reader` (#806) isn't on npm yet, and
`@developmentseed/geotiff` and `@developmentseed/deck.gl-geotiff` depend
on it. The publish workflow can't create it: it publishes only through
trusted publishing (OIDC), and npm can add a trusted publisher only to a
package that [already
exists](https://docs.npmjs.com/cli/v11/commands/npm-trust). Pushing the
tag first would fail at `range-reader`. `pnpm publish --recursive` stops
at the first failure, so packages published before it in the run would
be out, and the rest, including `geotiff` and `deck.gl-geotiff`, would
not.

Once this is merged, from an up-to-date `main`:

1. Publish it once, as a public package under the `beta` tag. Its
`prepublishOnly` script builds it first.
   ```sh
   cd packages/range-reader
   pnpm publish --tag beta --access public --no-git-checks
   ```
2. Give it the same trusted publisher as the other packages (workflow
`release.yml`, environment `release`), in its settings on npmjs.com or
with:
   ```sh
npm trust github @developmentseed/range-reader --file release.yml --repo
developmentseed/deck.gl-raster --env release --allow-publish
   ```
3. Tag the merge commit `v0.10.0-beta.1` and push the tag. The workflow
skips `range-reader`, since that version is already on npm, and
publishes the other ten packages.

## Breaking changes

- #799: `COGLayer` takes a single `source`: an opened `COGSource`, or
any input of `COGSource.open`. `geotiff` becomes `source`,
`onGeoTIFFLoad` becomes `onSourceLoad`, and `epsgResolver` and
`concurrencyLimiter` move to `COGSource.open`.
- #801: `MultiCOGLayer` does the same with `MultiCOGSource`. `sources: {
red: { url } }` becomes `source: { red: url }`, `MultiCOGSourceConfig`
is removed, and files that don't share a CRS and an extent are rejected.
- #804: `MosaicLayer`'s `sources` becomes deck.gl's `data`, and
`MosaicSource` becomes `MosaicItem`. The callbacks get the item's opened
source as `source`, and `onViewportLoad`'s entries are `{ item, source
}`.
- #821: `renderSource` gets only `{ source }`, without `signal`.
- #812: `ZarrLayer` takes a `ZarrSource`, or a zarrita group or array,
as `source`. `node`, `variable`, `metadata` and `epsgResolver` are
removed (`metadata` becomes `ZarrSource.open`'s `geoZarrMetadata`), and
the type parameters are now `ZarrLayer<DataT, Dtype, Store>`.
- #807: `GeoTIFF.fromUrl` no longer takes `chunkSize` or `cacheSize`.
They're `RangeReader` options now (`minMetadataReadBytes`,
`cache.metadataBytes`).

Two behavior changes aren't marked breaking:

- #809: COG tile reads are coalesced by default, and `COGLayer` and
`MultiCOGLayer` default to `maxRequests: 256` and `debounceTime: 50`.
- #818: changing `updateTriggers.getTileData`, or ZarrLayer's
`selection`, fetches tiles again, and the old tiles are removed at once.

🤖 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant