perf(grib): an open skips the data of a message's fields, and a remote dataset keeps no message it read for its nodata #1264
All Vouch review confidence checks passed
Residual risk 0.42 = Change Risk (0.52) × (1 − Review Confidence (0.19)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 26% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #1264"
general
weight: 0.35
github-actions[bot]
Opening a GRIB file no longer reads the data of a message's fields, and a remote dataset no longer keeps the GRIB1 messages it reads whole to work out their nodata. In a GRIB2 message of several fields, each field's sections come after the data of the field before it: to reach them, the open read that data (48 of the 64 MiB of a message of four 16 MiB fields), and a remote dataset kept it for as long as it was open. The open now skips the bodies of the data, bitmap and local use sections by their lengths, on both readers. That message's remote open now fetches 0.02 MiB in 4 requests, where it fetched 48.00 MiB in 22; its local open reads 0.02 MiB, where it read 48.01 MiB. A GRIB1 message whose nodata depends on its values is still read whole at open to work out its nodata, and is then dropped: eight such messages of 4.2 MiB held 33.7 MiB after a remote open and now hold 0.1 MiB, and a read of one of their bands fetches its message again.
Fixes #1215.
Behaviour
message_fields, which the in-memory reader and every decode use, parses a whole message as one run, with the same checks in the same order, so the bands, metadata, nodata and errors are those of the message read whole.mainasked for each section of a field after a skipped part separately). The extra bytes stop short of the message's end marker, and the next message's first request is sized from the bytes the header needed, as onmain: a damaged end marker fails a remote open where it did before. The dataset keeps of each message the bytes read in a row from its start, which a read of its bands does not fetch again, as onmain, but no longer the data of skipped fields, nor the zeros that stood for a skipped GRIB1 bitmap (2.0 MiB for the eight messages of the issue's script).docs/formats.md(GRIB: a request for each further field of a message, the GRIB1 messages read whole and dropped, a message of several fields fetched for each band read on its own, a local open skipping the fields' data) anddocs/remote-data.md(what a remote open reads).Before and after
The issue's script, which serves the files from a loopback server and counts the bytes it sends. On
main(e44e1126) it prints:On this branch:
fields.grib2is one message of four 16 MiB fields andmessages.grib2the same fields as four messages; the GRIB1 files hold eight messages with bitmaps, whose nodata depends on their values innodata-from-values.grb. A read of band 1 offields.grib2now fetches the message past its first 16 KiB, so the open and that read fetch 64.00 MiB, as before; a read of band 1 ofnodata-from-values.grbfetches its 4.2 MiB message again. Reads of the other bands offields.grib2fetch the message again too (see Limitations).Open times, medians of three rounds of 20 opens in one process (10 for the remote files and
nodata-from-values.grb, 5 for remotemany.grib2, six rounds of 60 for localmany.grib2andmessages.grib2), the remote files served by the same loopback server:| File |
main| This branch || --- | --- | --- |
|
fields.grib2, local | 18.89 ms | 0.40 ms ||
messages.grib2, local | 0.38 ms | 0.38 ms ||
many.grib2(696 messages of one 360 x 181 field), local | 24.72 ms | 24.34 ms ||
nodata-fixed.grb, local | 0.45 ms | 0.46 ms ||
nodata-from-values.grb, local | 212.97 ms | 214.20 ms ||
fields.grib2, remote | 110.18 ms | 3.37 ms ||
many.grib2, remote | 495.98 ms | 493.04 ms ||
nodata-fixed.grb, remote | 11.77 ms | 12.03 ms ||
nodata-from-values.grb, remote | 284.69 ms | 278.53 ms |An open, then a read of one pixel of each band, in a fresh process (medians of six runs): the MiB fetched by the open and by the reads, and their seconds.
| Remote file, bands read |
main| This branch || --- | --- | --- |
|
fields.grib2, one at a time | 48.00 + 64.00 MiB, 0.193 + 0.921 s | 0.02 + 255.94 MiB, 0.004 + 1.220 s ||
fields.grib2, together | 48.00 + 16.00 MiB, 0.167 + 0.569 s | 0.02 + 63.98 MiB, 0.004 + 0.767 s ||
uv.grib2(one message of two 1440 x 721 fields), one at a time | 1.98 + 3.96 MiB, 0.014 + 0.055 s | 0.02 + 7.89 MiB, 0.003 + 0.063 s ||
uv.grib2, together | 1.98 + 1.98 MiB, 0.014 + 0.046 s | 0.02 + 3.94 MiB, 0.003 + 0.047 s ||
nodata-from-values.grb, one at a time | 33.68 + 0 MiB, 0.295 + 0.233 s | 33.68 + 33.66 MiB, 0.292 + 0.292 s ||
nodata-fixed.grb, one at a time | 0.02 + 33.66 MiB, 0.014 + 0.350 s | 0.02 + 33.66 MiB, 0.014 + 0.329 s |The memory of the open, in the same runs (MiB: the peak during the open, then what the dataset holds after it):
| File |
main| This branch || --- | --- | --- |
|
fields.grib2, local | 63.2, 0.0 | 0.0, 0.0 ||
fields.grib2, remote | 79.5, 48.1 | 0.1, 0.1 ||
nodata-from-values.grb, remote | 56.0, 33.8 | 26.6, 0.2 ||
nodata-fixed.grb, remote | 2.1, 2.1 | 2.1, 0.2 |Reads that each decode their band, in one process (
TERRIO_CACHEMAX=0, the bands in turn; medians of three rounds):| File |
main| This branch || --- | --- | --- |
|
messages.grib2, local (a 16 MiB message per read) | 133.25 ms | 128.56 ms ||
fields.grib2, local (the 64 MiB message per read) | 161.08 ms | 159.03 ms ||
uv.grib2, local | 21.85 ms | 21.70 ms ||
nodata-fixed.grb, local | 30.64 ms | 29.56 ms ||
nodata-from-values.grb, local | 27.06 ms | 26.78 ms ||
uv.grib2, remote | 24.20 ms | 26.12 ms |Local reads, whose code this branch changes only in parsing a whole message as one run, take no longer than on
main. A remote read of a band ofuv.grib2fetches its whole 3.94 MiB message, wheremainfetched the 1.98 MiB past the field the open kept.Tests and mutations
a_message_of_several_fields_is_opened_without_their_data(local.rs): one message of four 512 x 256 Float32 fields is opened reading at most five pages, and its bands are those of the message read whole. With the data sections read whole, the open reads all 2,097,498 bytes of the message.a_grib2_header_skips_the_bodies_of_its_sections(local.rs): the header of the two fields oftwo_bands_with_bitmap.grib2as one message, the bodies of its local use, bitmap and data sections grown by 10,000 bytes each, is read without touching any of them (under 2,000 bytes), and describes the bands as the whole message does.a_lazy_grib_open_holds_one_message_header_at_a_time(tests/declared_size.rs) also checks that the open allocates nothing the size of a field (fields of 64 KiB; with the data sections read whole, its largest allocation is 262,486 bytes).test_remote_open_skips_the_data_of_a_message_s_fields(Python): four fields of 200,000 bytes in one remote message cost the first block and under 3 KiB more at open. Onmainit fails: 600,342 bytes.test_remote_grib1_by_rangenow also checks that a read of a band whose message was read whole at open fetches it again (onmain,[1]fails: the read fetches nothing, the message being kept); its ceiling and that oftest_remote_grib1_headers_skip_bitmapscount those messages twice.Each guarantee broken on purpose, then restored (the tree checked clean after each). Four of them (the data sections read whole, the walk by the bytes at hand, the remote GRIB1 message kept, and the read-ahead reaching the end marker) were run again on the branch rebased on
main, with the same result, the read-ahead's 48 outcomes differing frommain's:| Mutation | Caught by |
| --- | --- |
| A GRIB2 header needs the bodies of its data sections |
a_grib2_header_skips_the_bodies_of_its_sections,a_message_of_several_fields_is_opened_without_their_data,a_local_file_is_read_by_message, and indeclared_size.rsa_lazy_grib_open_allocates_nothing_the_size_of_its_fileanda_lazy_grib_open_holds_one_message_header_at_a_time|| ... the bodies of its bitmap sections |
a_grib2_header_skips_the_bodies_of_its_sections|| ... the bodies of its local use sections |
a_grib2_header_skips_the_bodies_of_its_sections|| The skipped parts held as zeros in one run (nothing more read) |
a_lazy_grib_open_holds_one_message_header_at_a_time|| The walk goes on past the bytes at hand of a cut section instead of by its length |
a_grib2_header_skips_the_bodies_of_its_sections,a_file_is_read_by_position_as_in_memory,a_message_of_several_fields_is_opened_without_their_data,the_fields_of_one_message_read_together_read_it_once|| A local GRIB2 message's end marker left unchecked when its header does not reach it |
a_file_is_read_by_position_as_in_memory|| A bitmap section's indicator octet not read with its header |
a_grib2_header_skips_the_bodies_of_its_sections,a_message_of_several_fields_is_opened_without_their_data,a_file_is_read_by_position_as_in_memory,the_fields_of_one_message_read_together_read_it_once, and indeclared_size.rsa_lazy_grib_open_holds_one_message_header_at_a_time|| A header's adjacent parts kept as separate runs, never joined | the same five, and
a_remote_grib_without_a_grib_extension_is_read_by_range|| A remote GRIB1 message read whole for its nodata kept |
test_remote_grib1_by_range[1]|| A remote GRIB1 header kept with the zeros of its bitmap |
test_remote_grib1_by_range[4],test_remote_grib1_headers_skip_bitmaps[1]and[7]|| The remote read-ahead reaching the end marker | the remote differential check below: 48 of 19,720 outcomes differ |
| The next remote message's first read sized from the first run, read-ahead included | the remote differential check: 16 outcomes differ |
#1163's differential check, now on
main(every byte of the small fixtures and of the GRIB1 file of four messages damaged four ways, and the file cut there, read by position and in memory), with four messages of several fields made of two-message fixtures added: 341,895 cases, 127,351 of them errors, the same by position and in memory in every case, on this branch and onmain, and the in-memory outcomes of the two the same in every case. A remote one, temporary like it: damaged files (four messages of two fields whose first field's data is padded past a block, a GRIB1 file of four messages with bitmaps, and a file of a GRIB1 message, the padded message and a 15,501-byte message), served by range, opened and read band by band withmain's build and this branch's: 19,720 cases, the same outcome (bands, metadata, values or error) in every case.Checks run
On this branch's code (a0a0c5ac: two commits on
maine44e1126), with Rust 1.95 unless said:cargo fmt --all -- --check: passed.cargo clippy -p terrio -p terrio-py --all-targets --no-deps -- -D warningspasses with Rust 1.99.1, and with Rust 1.95 with-Afor the four lints thatmainhas elsewhere interrio(nonminimal_bool,collapsible_match,collapsible_if,drop_non_drop: 25 in 18 files, none of which this branch changes).cargo clippy --workspace --all-targets -- -D warningspasses with Rust 1.99.1.cargo test -p terrio: 3,669 passed, 55 ignored; the GRIB and block cache unit tests (48) andtests/declared_size.rs(39) also on their own.RUSTFLAGS="-D warnings" cargo hack check -p terrio --each-feature --no-dev-deps --exclude-features gdal: passed.cargo +1.90 check --workspace --all-targets --locked: passed.cargo build -p terrio --target wasm32-unknown-unknown: passed, with no warning in the GRIB driver.RUSTDOCFLAGS="-D warnings" cargo doc -p terrio -p terrio-crs --no-deps: passed.python -m pytest tests/test_grib.py tests/test_grib_gdal.py tests/test_resource_limits.py tests/test_remote_reads.py, with the extension built from a0a0c5ac: 236 passed, 19 skipped, 3 xfailed. The whole Python suite (-n 6 --dist loadfile): 9,991 passed, 2,286 skipped, 4 xfailed, 2 xpassed.ruff checkandruff format --checkon the Python test file changed: passed.reuse lint: compliant. No Python package code changes.Limitations
fields.grib2one at a time fetches 255.9 MiB in 1.22 s, wheremainfetched 48.0 MiB at open and 64.0 MiB for the reads (1.11 s in all); for the two fields ofuv.grib2, 7.9 MiB wheremainfetched 5.9 MiB. Bands read together are decoded from one fetch of their message: 64.0 MiB forfields.grib2, as many asmainfetched in all (0.77 s, against 0.74 s). Keeping a fetched message of several fields for the next read of its bands, within the block cache's budget, would avoid the refetch; it is not part of this change.mainfetched 33.68 MiB in 0.53 s. Keeping the message would keep the file.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Improvements
GRIB datasets can now be opened when message headers are split across separate byte ranges or read in partial sections.
Opening local GRIB2 files skips field data between section headers, reducing unnecessary data reads.
Remote GRIB reads now fetch field data as needed, with clearer handling of multi-field messages and GRIB1 messages that require data to determine nodata values.
Documentation
Updated GRIB guidance to clarify remote request behavior and data reads during open and band access.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->