Skip to content

fix(range-reader): request cap for adjacent reads, round-robin launches, 1 MiB default - #815

Merged
kylebarron merged 5 commits into
mainfrom
kyle/range-reader-adjacent-cap
Oct 28, 2026
Merged

kylebarron merged 5 commits into
mainfrom
kyle/range-reader-adjacent-cap

Conversation

@kylebarron

@kylebarron kylebarron commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

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

🤖 Generated with Claude Code

A read that started exactly where the current range ended was treated
like an overlapping one and joined unconditionally, so the tiles of a COG
row, which are contiguous, merged without any bound and `maxRequestBytes`
never applied: ten 2.4 MB tiles became one 24 MB request. Measured
tonight, that is why big-tile views ran on two or three streams and were
slower than unmerged requests on a fast link with latency, and why the
first tile arrived seconds later inside a merged run. Only a read that
starts before the range's end, a true overlap, joins past the cap now.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions Bot added the fix label Oct 28, 2026
kylebarron and others added 2 commits October 28, 2026 01:02
A limiter serves streams in the order they were launched, and the reads
of COG tiles carry no priority, so launching every merged 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: in the benchmark, sentinel-2's first tile arrived 2.5 s after
the jump at every request cap, against 0.5 s unmerged. Ranges are now
launched round-robin across the task's files.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
From the cap sweep (1 to 16 MiB, three link conditions, three examples):
with 2.4 MB tiles, caps of 8 MiB and more merged a view into two or
three streams and ran at 0.5-0.8x of unmerged requests on native and
fast links; 1-4 MiB stayed at parity on totals and kept small tiles
merging dozens to one. 4 MiB keeps the request-count win for mid-size
tiles; 1 MiB would bring the first tile closer to unmerged at the cost
of more requests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kylebarron kylebarron changed the title fix(range-reader): apply the request cap to adjacent reads fix(range-reader): request cap for adjacent reads, round-robin launches, 4 MiB default Oct 28, 2026
The final pass with both fixes in showed 4 MiB still costs NAIP's 460 KB
tiles 25% on a home link (merged in fours), consistent with the sweep's
2-16 MiB cells, while 1 MiB (pairs) was at parity or better. 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 2-4x faster; 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 is a follow-up.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kylebarron kylebarron changed the title fix(range-reader): request cap for adjacent reads, round-robin launches, 4 MiB default fix(range-reader): request cap for adjacent reads, round-robin launches, 1 MiB default Oct 28, 2026
Comment thread packages/range-reader/src/merge.ts Resolved
Comment thread packages/range-reader/src/reader.ts Resolved
The default-cap docstring states the rule and points at #815 for the
measurements instead of restating them; the merge docstring no longer
cites the private repository the rule was ported from.

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

@kylebarron kylebarron left a comment

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.

✅

@kylebarron
kylebarron merged commit ec82212 into main Oct 28, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/range-reader-adjacent-cap branch October 28, 2026 16: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 28, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

The range reader design spec cited the private prototype it grew from by
repository, commit and file, in four places. Those links are dead for
anyone but their owner, so the spec now names the prototype and its
results without them. No other tracked file mentions the repository; the
one docstring that did was fixed in #815.

🤖 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]>
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.

1 participant