Skip to content

feat!: make Jp2Metadata.color_specifications a MetadataList - #781

Merged
D0ubleD0uble merged 3 commits into
mainfrom
feat/780-colr-metadata-list
Nov 30, 2026
Merged

D0ubleD0uble merged 3 commits into
mainfrom
feat/780-colr-metadata-list

Conversation

@D0ubleD0uble

@D0ubleD0uble D0ubleD0uble commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Closes #780

Jp2Metadata::color_specifications is now a MetadataList<ColorSpecification>, like xml, uuid, ipr and uuid_info. Every list on Jp2Metadata has one type.

What changed

  • color_specifications (src/jp2/metadata.rs) and jp2::Lists::colr (src/jp2/payloads.rs) hold a MetadataList.
  • color_specifications() in src/jp2/mod.rs builds the list through list::Extender, the same code the other lists use. The measure pass pushes nothing.
  • How the list is shared. metadata() now clones the kept list on every read, one-shot or incremental. A MetadataList clone is two Arc bumps and a count, so it costs the same whatever the number of boxes. That let me remove the throwaway branch, which took the specs out of the one-shot Lists to avoid an O(n) Vec clone. That branch no longer saves anything, and one path is simpler than two. The colr list is read once per walk (kept.colr.is_none()), as before, and it is never extended, so no table slot can conflict.
  • The RestrictedIcc profile is still a clone of the chosen entry's Payload, so it shares that box's allocation.
  • No change in behavior. docs/stability.md already lists MetadataList and does not name field types, so it needs no edit. The README and examples do not use color_specifications.

Acceptance -> tests

Criterion Test
MetadataList, built through the crate's list code; a header() call with no new colr shares the previous list without copying it New header_shares_the_colr_list_across_calls (tests/incremental_header_payloads.rs): 130 colr boxes (two full blocks and a tail of 2). Every entry has the same address across a repeat call and across a call after more boxes are fed
ICC profile shares the colr payload The existing header_shares_the_payloads_of_whole_boxes_across_calls (one-shot and header), plus the same pointer check on all three headers in the new test
One-shot colr rows measured Below; docs/resource-bounds.md updated
CHANGELOG / stability / rustdoc / examples The CHANGELOG "Migrating from 0.5" entry names color_specifications (#769, #780). The rest already matched
Tests and examples compile; full gate Below
Auto traits tests/auto_traits.rs adds MetadataList<ColorSpecification>

Mutation checks. I applied each mutation to the committed tree, confirmed it was in place, and restored it from a backup.

  • M1: deep-copy the kept list on each call. The new test fails on the entry addresses.
  • M2: re-read the colr boxes on every call (read_colr = true). The new test and header_shares_the_payloads_of_whole_boxes_across_calls both fail.

The new test also compiles on main, where the Vec clone gives new addresses, the same failure as M1.

Measured (release, nice -n 19, 1-minute load about 1)

The one-shot rows use the method in docs/resource-bounds.md: tests/fixtures/jp2_sycc_422_even.jp2 plus 16 MiB of boxes, one decode per run, peak from /usr/bin/time -v, held = RSS after decode minus RSS before. Each figure is in MiB, steady over 3 rounds. main is ded9851.

Row Peak main Peak now Held main Held now
zeros (baseline) 18.7 18.6 0.7 0.7
colr inside jp2h (11 bytes, empty) 123.3 124.9 47.4 48.7
colr inside jp2h (12 bytes) 114.7 116.0 43.5 44.7
colr after jp2c (15 bytes) 44.1 44.1 0.8 0.8
colr after a padded jp2c (15 bytes) 44.1 44.1 0.8 0.7

The main figures reproduce the doc's figures. The jp2h rows rise by 1.4 to 1.6 MiB peak and 1.2 to 1.3 MiB held over 1.4 to 1.5 million entries, about 0.9 bytes an entry. The cause is the block headers and the block table that every MetadataList pays. Before, the entries sat in one Vec of exact size. The doc already states this cost (about 0.75 bytes an entry) for the other lists. The 11-byte figures per byte move from 6.5 / 3.0 to 6.6 / 3.0. The 15-byte rows do not move, since a colr after the codestream is not reported. I updated the two rows, the per-byte figure and the method note in docs/resource-bounds.md.

Repeat header() on the 11-byte file (1,525,202 colr, fed whole, 20 more calls with every header held): main 108 ms a call and 931 MiB more held; now 93 to 95 ms a call and 0 MiB more held. The rest of the call is reading jp2h again.

tests/incremental_header_cost.rs (ignored tests, release), main / now:

  • jp2h of free of length 0: 43 / 53 ms (one read 39 / 49 ms)
  • jp2h of colr of length 0: 47 / 57 ms (one read 40 / 50 ms)
  • pclr of length 0: 5.0 / 5.2 ms
  • a million 8-byte xml : 33 / 33 ms
  • a million 9-byte xml : 31 / 31 ms
  • open xml / uuid / jp2i: 9.4, 7.0, 7.0 / 7.9, 7.3, 7.3 ms

None of these files holds more than one colr before the codestream. The slowdown on the jp2h rows repeats, so it is not noise: it is a codegen-unit artifact, and with CODEGEN_UNITS=1 this branch is slightly faster than main. One read moves by the same amount. All pass, and no doc number changes.

Gate (rustc 1.100.1 after rustup update stable, niced, -j 2)

  • cargo fmt --all -- --check: ok
  • cargo clippy --all-targets -- -D warnings: ok
  • cargo clippy --lib -- -D warnings: ok
  • cargo test: ok (113 test binaries, 0 failed)
  • After the review fixes (21a325e): cargo fmt --check ok, cargo doc -D warnings ok, incremental_header_list_alloc prints again 692 (48 held) (main 80; the 32 bytes were the one-entry Vec<ColorSpecification> clone), so the header rustdoc and docs/incremental-decoding.md now say 48 bytes.
  • cargo deny check: ok
  • RUSTDOCFLAGS=-D warnings cargo doc --no-deps: ok
  • cargo test --target wasm32-wasip1 --lib: 852 passed, 0 failed

🤖 Generated with Claude Code

https://claude.ai/code/session_01EhjiZ6QTR3gTC3QaD9m2QV

@D0ubleD0uble
D0ubleD0uble merged commit 2b85059 into main Nov 30, 2026
15 checks passed
@D0ubleD0uble
D0ubleD0uble deleted the feat/780-colr-metadata-list branch November 30, 2026 00:40
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/jp2/mod.rs 85.7% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat!: make Jp2Metadata.color_specifications a MetadataList

2 participants