Repository navigation
Read files in place for metadata, and decode only image headers - #103
Merged
Merged
Conversation
GetMetadata read every input into memory before running its handlers, so indexing a large video read all of it into memory, once for each file being indexed. An input which can be read at an offset and seeked, such as a file, is now read in place: each handler has its own section reader of it, so it reads only what it needs, and the input's position is unchanged. Other inputs are read into memory once, as before, and each handler can seek in them too. The image handler decodes the image's format and size from its header, rather than decoding the whole image. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused changes and regression tests have no identified blocking issues.
0 open findings
What changed in this PR
Reduces metadata extraction memory use by reading seekable inputs in place and decoding only image headers.
Changes:
- Gives handlers independent section readers, retaining buffering for other inputs.
- Uses
image.DecodeConfigfor image format and dimensions. - Tests seeking, filename preservation, unchanged file position, and buffering fallback.
| File | Description |
|---|---|
| metadata/metadata.go | Adds in-place reading with a buffered fallback. |
| metadata/metadata_test.go | Tests both reader paths and handler isolation. |
| metadata/image/image.go | Extracts dimensions without decoding pixels. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Extracting metadata from large files used a lot of memory.
Changes
metadata.GetMetadatacopied every input into memory before running its handlers, so a large video was read in full.*os.File, is now read in place. Each handler gets its ownio.SectionReaderof the input, from its current position.image.DecodeConfiginstead ofimage.Decodeto get the format, width and height, rather than decoding every pixel.Testing
Test_metadata_014: handlers read a file from its current position, can seek in it, and get its name. The file's position is unchanged afterwards.Test_metadata_015: a reader that can't be read at an offset is read into memory, and handlers can still seek in it.