Repository navigation
feat!: make Jp2Metadata.color_specifications a MetadataList - #781
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhjiZ6QTR3gTC3QaD9m2QV
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhjiZ6QTR3gTC3QaD9m2QV
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhjiZ6QTR3gTC3QaD9m2QV
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #780
Jp2Metadata::color_specificationsis now aMetadataList<ColorSpecification>, likexml,uuid,ipranduuid_info. Every list onJp2Metadatahas one type.What changed
color_specifications(src/jp2/metadata.rs) andjp2::Lists::colr(src/jp2/payloads.rs) hold aMetadataList.color_specifications()insrc/jp2/mod.rsbuilds the list throughlist::Extender, the same code the other lists use. The measure pass pushes nothing.metadata()now clones the kept list on every read, one-shot or incremental. AMetadataListclone is twoArcbumps and a count, so it costs the same whatever the number of boxes. That let me remove thethrowawaybranch, which took the specs out of the one-shotListsto avoid an O(n)Vecclone. That branch no longer saves anything, and one path is simpler than two. Thecolrlist is read once per walk (kept.colr.is_none()), as before, and it is never extended, so no table slot can conflict.RestrictedIccprofile is still a clone of the chosen entry'sPayload, so it shares that box's allocation.docs/stability.mdalready listsMetadataListand does not name field types, so it needs no edit. The README and examples do not usecolor_specifications.Acceptance -> tests
MetadataList, built through the crate's list code; aheader()call with no newcolrshares the previous list without copying itheader_shares_the_colr_list_across_calls(tests/incremental_header_payloads.rs): 130colrboxes (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 fedcolrpayloadheader_shares_the_payloads_of_whole_boxes_across_calls(one-shot andheader), plus the same pointer check on all three headers in the new testcolrrows measureddocs/resource-bounds.mdupdatedcolor_specifications(#769, #780). The rest already matchedtests/auto_traits.rsaddsMetadataList<ColorSpecification>Mutation checks. I applied each mutation to the committed tree, confirmed it was in place, and restored it from a backup.
colrboxes on every call (read_colr = true). The new test andheader_shares_the_payloads_of_whole_boxes_across_callsboth fail.The new test also compiles on
main, where theVecclone 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.jp2plus 16 MiB of boxes, onedecodeper run, peak from/usr/bin/time -v, held = RSS afterdecodeminus RSS before. Each figure is in MiB, steady over 3 rounds.mainis ded9851.colrinsidejp2h(11 bytes, empty)colrinsidejp2h(12 bytes)colrafterjp2c(15 bytes)colrafter a paddedjp2c(15 bytes)The
mainfigures reproduce the doc's figures. Thejp2hrows 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 everyMetadataListpays. Before, the entries sat in oneVecof 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 acolrafter the codestream is not reported. I updated the two rows, the per-byte figure and the method note indocs/resource-bounds.md.Repeat
header()on the 11-byte file (1,525,202colr, 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 readingjp2hagain.tests/incremental_header_cost.rs(ignored tests, release), main / now:jp2hoffreeof length 0: 43 / 53 ms (one read 39 / 49 ms)jp2hofcolrof length 0: 47 / 57 ms (one read 40 / 50 ms)pclrof length 0: 5.0 / 5.2 msxml: 33 / 33 msxml: 31 / 31 msxml/uuid/jp2i: 9.4, 7.0, 7.0 / 7.9, 7.3, 7.3 msNone of these files holds more than one
colrbefore the codestream. The slowdown on thejp2hrows repeats, so it is not noise: it is a codegen-unit artifact, and withCODEGEN_UNITS=1this 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: okcargo clippy --all-targets -- -D warnings: okcargo clippy --lib -- -D warnings: okcargo test: ok (113 test binaries, 0 failed)cargo fmt --checkok,cargo doc -D warningsok,incremental_header_list_allocprintsagain 692 (48 held)(main 80; the 32 bytes were the one-entryVec<ColorSpecification>clone), so theheaderrustdoc anddocs/incremental-decoding.mdnow say 48 bytes.cargo deny check: okRUSTDOCFLAGS=-D warnings cargo doc --no-deps: okcargo test --target wasm32-wasip1 --lib: 852 passed, 0 failed🤖 Generated with Claude Code
https://claude.ai/code/session_01EhjiZ6QTR3gTC3QaD9m2QV