Skip to content

Cache per-video pose attributes to skip load-time pose scan (KLAUS-506)#413

Open
gbeane wants to merge 2 commits into
mainfrom
feature/klaus-506-pose-attribute-cache
Open

Cache per-video pose attributes to skip load-time pose scan (KLAUS-506)#413
gbeane wants to merge 2 commits into
mainfrom
feature/klaus-506-pose-attribute-cache

Conversation

@gbeane

@gbeane gbeane commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Caches the per-video pose attributes read at project load (frame count, identity count, static objects, lixit keypoints, cm-per-pixel) so subsequent loads rescan only new/changed pose files instead of opening all of them.

Measured on a 488-video project (external SSD): cold load 3.88s (488 pose scans) → cached load 0.01s (0 scans), with identical identity counts and pose version.

What changed

  • New jabs/cache/pose_attribute_cache.json, keyed by video filename and gated by a cheap stat token (size:mtime_ns) of the pose file; schema-versioned.
  • New module pose_attribute_cache.py (pose_token / load / save); ProjectPaths.pose_attribute_cache_file (returns None when use_cache=False).
  • _run_video_scan split into _scan_jobs + _run_cached_video_scan. The opt-in enable_video_check path bypasses the cache, since video frame counts are not cached.
  • Transparent to VideoManager / FeatureManager (same VideoScanResult); no consumer changes.

Behavior

  • Missing / corrupt / schema-mismatched cache → full rescan (self-healing; existing projects upgrade lazily on first load, no migration).
  • A changed pose file (new stat token) or a pose-version upgrade invalidates that entry; removed videos are pruned.
  • clear_cache() removes the file harmlessly; use_cache=False → no persistence.

Tests

13 new tests: module unit tests plus cache-hit (no rescan), token invalidation, new-video-only scan, use_cache=False, and fresh-vs-cached parity. Full suite green.

Jira: KLAUS-506

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.

Pull request overview

Introduces a persistent, per-video cache of pose-derived metadata to avoid opening and scanning every pose HDF5 file on subsequent project loads, significantly reducing load time for large projects.

Changes:

  • Added pose_attribute_cache module to load/save a schema-versioned JSON cache keyed by video filename and pose-file stat token.
  • Updated Project._run_video_scan to reuse cached per-video pose attributes and rescan only new/changed pose files (while bypassing cache when enable_video_check=True).
  • Added unit + integration-style tests covering cache hits, invalidation, new-video-only scans, and use_cache=False.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/project/test_pose_attribute_cache.py Adds tests validating cache persistence, cache-hit behavior, and invalidation scenarios.
src/jabs/project/project.py Implements cached scan path and reconstructs scan results from cached pose attributes.
src/jabs/project/project_paths.py Adds pose_attribute_cache_file path helper (returns None when caching is disabled).
src/jabs/project/pose_attribute_cache.py New module handling token generation and resilient cache load/save.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +76 to +83
def _pose_cache_entry_matches(entry: object, token: str, pose_file: str) -> bool:
"""Return True when a cache entry is usable for a video's current pose file."""
return (
isinstance(entry, dict)
and entry.get("token") == token
and entry.get("pose_file") == pose_file
and all(field in entry for field in _POSE_CACHE_FIELDS)
)
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.

2 participants