Repository navigation
mxf: adaptive read window while walking KLVs at open (reads 8x less for intra files) - #3279
Conversation
The open walk refilled its window with 64 KiB on every miss. With big elements (intra pictures, clip-wrapped sound) the next KLV header sits behind a long jump, so every header cost a 64 KiB read and most of it was thrown away: opening read 33 to 97 percent of the file. After a value of 64 KiB or more the refill is 4 KiB for the next four KLVs (a frame holds several elements and not all are big); with small KLVs it stays at 64 KiB as before, so dense small-frame files read exactly what they did. Also copies the 25 header bytes into an array instead of allocating a Vec per KLV. The parse result is identical (Debug hash of tracks, partitions, index segments, timecode and warnings unchanged on DNxHD, ProRes, MPEG-2 and AVC fixtures). Adds a test that opening a file of 200 KB pictures reads under a fifth of it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Adaptive KLV refill and validation crates/mxf/src/file.rs, crates/mxf/src/write/tests.rs |
Refills use 64 KiB normally and 4 KiB for four KLVs after a value of at least 64 KiB. Headers use a fixed 25-byte buffer. The test checks discovery of 40 picture samples and verifies that opening reads less than one-fifth of the file. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Refactor
Suggested reviewers: echelon, earlvanze
Merge Risk: 
Minimal · up to 04167
-
No actionable risk remains identified for this MXF reading change; it is ready for normal merge checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed -
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Usage-based review receipt
- Mode: Continue automatically
- Reviewed files: 2
- Waived: $0.50 (charged $0.00)
- View usage details
Note
This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.
Comment @coderabbitai help to get the list of available commands.
|
This PR is one of four from a speed audit of the MXF container code (
Notes:
|
FredApps
left a comment
There was a problem hiding this comment.
Approving. While walking the KLVs at open, the MXF reader's window now refills with 4 KiB instead of 64 KiB for the next four KLVs after any value of 64 KiB or more, since the next header after a big picture is only a few bytes and the rest of a big read would be skipped by the next jump. Window::skipped(vlen) is called once per KLV at the end of the loop, and the 25-byte header is copied into a stack array instead of a Vec. The new test counts bytes read through a ByteSource on a file of 40 frames with ~200 KB pictures and asserts that open reads less than a fifth of the file. I read the whole diff; the gate and SonarCloud pass at 041670e. I read the code and the CI results; I did not run the app.
Part of #3261 (decode_pcm/AES3 is #3276, the caller side follows)
What
walk()refilled itsWindowwith 64 KiB on every miss. With big elements (intra pictures, clip-wrapped sound) the next KLV header lies behind a long jump, so each header cost a 64 KiB read that was mostly thrown away.Now the refill is 4 KiB for the next four KLVs after a value of 64 KiB or more, and 64 KiB otherwise. Files with small frames keep exactly the old read pattern. The 25 header bytes are copied into an array instead of a
Vecper KLV. The design option of opening from the RIP/index is not part of this.Proof
tracks,partitions,index_segments,timecode,warningsis the same before and after on four ffmpeg-made fixtures (DNxHD 36M 1080p + PCM24, ProRes 720p + PCM16, MPEG-2 long GOP 320x240, AVC long GOP with B frames).open_does_not_read_through_big_pictures(fails on the old code: 2.7 MB of 8.3 MB read).cargo test --release -p filmcraft-mxf31 passed,-p filmcraft-codecs mxf(incl. the ffmpeg oracle) passed, clippy-D warnings,fmt --check.Measurement
File-backed
ByteSource(pread) with read counter, 20 s fixtures:Bytes read drop about 8x for intra files, but the number of reads doubles (one 4 KiB read for each of the two elements of a frame instead of one 64 KiB read per frame). On cold local storage, NAS or blob sources the byte volume dominates; on a very high-latency source with no read-ahead the doubled request count could matter.
Overlap with open PRs
#1794 touches
file.rsat line 241 only (no overlap). #1056 editswalk()(hunks around lines 327-400), the same area as this change; the edits are small and local, a manual merge of theWindow/walkheader lines is needed. #1078 touchesfile.rsatbuild_trackonly. PR #3274 and this PR both append a test at the end ofwrite/tests.rs: trivial add/add conflict for whichever merges second.🤖 Generated with Claude Code
Summary by CodeRabbit