Skip to content

perf(assets): stream MD5 checks for cached assets - #3031

Open
voropaevv wants to merge 4 commits into
roboflow:developfrom
voropaevv:perf/stream-asset-md5
Open

voropaevv wants to merge 4 commits into
roboflow:developfrom
voropaevv:perf/stream-asset-md5

Conversation

@voropaevv

@voropaevv voropaevv commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

download_assets checks the MD5 of an existing cached asset on every call. The check currently reads the entire file into a Python bytes object. Stream the same digest in 1 MiB chunks so validation does not require a file-sized buffer.

Motivation and Context

The catalog's vehicles.mp4 is 35,345,757 bytes. On macOS with Python 3.11.17, five warmed cached download_assets(VideoAssets.VEHICLES) calls produced these medians, using the same verified video and environment in a fresh process per revision:

Measurement develop This change
Peak Python allocations during cached validation 35,351,034 bytes 2,102,881 bytes
Elapsed time per call 38.11 ms 42.51 ms

This is a 94% reduction in traced Python allocation for this path. Timing is included for context; these measurements support a memory improvement, with no speedup claim. They measure cached hash validation rather than process RSS or video decoding. No network requests occurred during the measured calls. The catalog MD5 matched on both revisions.

Minimal local reproduction after downloading the asset once:

import tracemalloc

from supervision.assets import VideoAssets, download_assets

download_assets(VideoAssets.VEHICLES)
tracemalloc.start()
download_assets(VideoAssets.VEHICLES)
print(tracemalloc.get_traced_memory()[1])
tracemalloc.stop()

Changes Made

  • Update the existing MD5 incrementally, preserving the signature, missing-file result, case-sensitive comparison and existing download flow.
  • Add real-file reference, complete-tail, bounded-read/allocation, error/cancellation and cached public-path coverage. The allocation measurement runs in a child process so it preserves caller-owned tracing.
  • Document the bounded check and add an Unreleased changelog entry.

Testing

Changelog integration update (20 November 2026): merged f094e33e and retained the #3031, #2954 and #2956 entries. The MD5 implementation and its tests are unchanged. Two complete local runs each finished with 7,571 passed / 283 skipped; full pre-commit run --all-files also passed twice. Hosted CI results are a separate gate.

Earlier validation of the original MD5 change:

  • pytest --cov=supervision --cov-report=xml: 7,542 passed, 283 skipped. The baseline had 7,524 passed and the same skips; every baseline test retained its outcome.

  • pytest tests/assets/test_downloader.py tests/assets/test_list.py -q: 38 passed.

  • UV_NO_SYNC=1 pre-commit run --all-files: passed, including mypy.

  • The allocation test also passed with PYTHONTRACEMALLOC=1; pre-existing parent tracing and an earlier object's traceback remained intact.

  • Final tests reject the original full-buffer implementation, a first-chunk-only implementation and an implementation that retains all chunks before hashing.

  • Added/updated tests, and the full suite passes locally

  • Updated docstrings for the existing helper

  • Added an entry at the top of docs/changelog.md

Additional Notes

Local validation used the default NumPy fallback backend and the documented development/metrics dependencies. Optional framework integrations and hosted platform checks remain separate. Python 3.10-compatible APIs are retained; no dependencies or lockfile changed.

Hosted CI on d90c81f5

The hosted test matrix, integrations and documentation build passed. The links check failed on 50 historical changelog URLs returning HTTP 404; all 50 are already present in the pinned base cdb0fa0f. The new link to this PR returned HTTP 200 in that same job. The link-check configuration is unchanged.

@voropaevv
voropaevv requested a review from SkalskiP as a code owner November 19, 2026 16:46
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95%. Comparing base (f9f5ee6) to head (c2c43fc).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #3031   +/-   ##
=======================================
  Coverage       95%     95%           
=======================================
  Files           84      84           
  Lines        15503   15504    +1     
=======================================
+ Hits         14772   14773    +1     
  Misses         731     731           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda Borda added the enhancement New feature or request label Nov 20, 2026
@Borda
Borda requested a balanced review from Copilot November 20, 2026 13:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the bounded-memory checksum change.

No open issues 🎉

What changed in this PR

Reduces memory use during asset validation by streaming MD5 checks in 1 MiB chunks instead of loading entire files. Existing checksum comparison and download behavior remain unchanged; this is a memory improvement, not a claimed speedup.

Changes:

  • Updates the hash helper to process files incrementally.
  • Adds coverage for digest correctness, bounded reads and allocations, error cleanup, and cached downloads.
  • Documents the bounded-memory behavior and adds an Unreleased changelog entry.
File Description
tests/​assets/​test_downloader.py Adds streaming, memory-bound, failure-path, and cache-validation tests.
src/​supervision/​assets/​downloader.py Streams MD5 updates in 1 MiB chunks and updates the docstring.
docs/​changelog.md Records the memory improvement and updates the modification date.

Review effort: Balanced

This branch has not been deployed

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants