Skip to content

Scan reads embedded XMP from metadata, not by re-reading whole files - #311

Open
erhangundogan wants to merge 5 commits into
mainfrom
xmp-scan
Open

erhangundogan wants to merge 5 commits into
mainfrom
xmp-scan

Conversation

@erhangundogan

Copy link
Copy Markdown
Collaborator

After hashing, scan read every new file whole into memory (and copied it again) to find embedded XMP, one file at a time: 61 MP4s (21 GB) spent 2.4 minutes there after a 1-minute hash, and a large video cost about twice its size in RAM.

Embedded XMP only lives in metadata, and content_key already finds those spans, so the reader now searches only them via content_key::metadata. Formats it does not parse are still searched whole.

A counting-reader test proves a video's media samples are not read. On a 999-file, 4.4 GB sample a fresh scan went from 34 s to under 2 s with identical stored results.

After the hashing pass, scan reconciles XMP for every file it just hashed,
and read_data_in found the embedded packet by reading the entire media file
into memory, copying it again through String::from_utf8_lossy, and
searching the text, one file at a time. A folder of 61 MP4s (21 GB) spent
one minute hashing and 2.4 minutes here; a large video briefly cost about
twice its size in RAM. faces' XMP readback used the same path.

An embedded packet only ever sits in metadata: JPEG APP1, PNG iTXt, WebP's
XMP chunk, TIFF tag 700, a HEIC's mime item, a movie's boxes other than
mdat. content_key already finds exactly those spans by reading block headers
for the metadata hash, so content_key::metadata returns their bytes (a span
over 64 MB is skipped) and the reader searches only them, with the same
confinement and size-scaled timeout as before. A format content_key does not
parse is still searched whole, so no packet videre used to find is lost.

No XMP crate fits: xmp_toolkit wraps Adobe's C++ SDK, nom-exif centres on
EXIF under a non-standard license, img-parts covers JPEG, PNG and RIFF only;
the span parser here already handles all eight formats.

A test reads a video's packet through a counting reader and asserts the
8 MB of media samples are never read; it read all of them before. On a
999-file, 4.4 GB sample a fresh scan went from 34 s to under 2 s, storing
identical rows and the same XMP-derived mark.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://xmp-scan-videre-doc.erhan-gundogan.workers.dev (commit a88a38f)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://49c6e6a0-videre-doc.erhan-gundogan.workers.dev a88a38f 2026-11-27T16:48:09.900Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://b452fa6c-videre-doc.erhan-gundogan.workers.dev 60549bb 2026-11-26T12:48:27.210Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://8f11faa4-videre-doc.erhan-gundogan.workers.dev aa43b8c 2026-11-25T13:14:19.828Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://0ca378d8-videre-doc.erhan-gundogan.workers.dev 8be085c 2026-11-23T11:35:05.120Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://3ae5ed17-videre-doc.erhan-gundogan.workers.dev 968e748 2026-11-20T14:05:08.862Z Visit the dashboard ↗

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.

1 participant