Skip to content

Performance and observability improvements#5

Merged
vladiant merged 6 commits intomainfrom
minor_fixes
Mar 29, 2026
Merged

Performance and observability improvements#5
vladiant merged 6 commits intomainfrom
minor_fixes

Conversation

@vladiant
Copy link
Copy Markdown
Collaborator

Version: 1.1.0 → 1.2.0 (MINOR)

Summary

This MR addresses three performance bottlenecks and one observability gap: uncached metadata fetches, unbounded in-memory result loading, a scalar-only C++ resize path with Python list copy overhead, and a health endpoint that hardcoded its version and performed no dependency checks.

Changes

In-memory metadata cache

  • Added CachedImageRepository decorator (infrastructure layer) wrapping PostgresImageRepository with a thread-safe, TTL-based in-memory cache for get_by_id lookups.
  • Cache is invalidated on save and delete to maintain consistency; list_images, count, and get_expired pass through uncached.
  • Configurable via IMG_CACHE_TTL_SECONDS (default 60) and IMG_CACHE_MAX_SIZE (default 1024).

Server-side cursors for list queries

  • list_images() and get_expired() switched from session.execute() + .scalars().all() to session.stream_scalars() with async iteration, using PostgreSQL server-side cursors to avoid loading entire result sets into memory.

C++ SIMD optimization and zero-copy I/O

  • bilinear_resize now uses SSE2 intrinsics on x86-64 to interpolate all channels per pixel in parallel (__m128 float ops), with a scalar fallback for other architectures.
  • Input/output changed from std::vector<uint8_t> (copied element-by-element from/to Python lists) to py::array_t<uint8_t> (zero-copy NumPy arrays).
  • CMake builds with -march=native for host-optimal SIMD codegen.

Health endpoint enhancements

  • Version is now read from importlib.metadata (sourced from pyproject.toml) instead of hardcoding "1.0.0".
  • Endpoint verifies database connectivity (SELECT 1) and storage directory existence.
  • Response includes a checks map with per-component status/detail; overall status is "degraded" if any check fails.

Files changed (14 files, +585 −53)

File Change
in_memory_cache.py New — TTL cache with max-size eviction
cached_image_repository.py New — Repository decorator
init.py New — Package init
test_cached_repository.py New — 16 tests for cache + decorator
postgres_image_repository.py stream_scalars for list queries
health.py DB/storage checks, dynamic version
image_schemas.py ComponentCheck model, checks field
dependencies.py Cache wiring, settings import
config.py cache_ttl_seconds, cache_max_size settings
test_api.py Updated health test with mock DB check
fast_resize.cpp SSE2 SIMD, py::array_t I/O
CMakeLists.txt -march=native
pyproject.toml Version bump to 1.2.0
CHANGELOG.md New [1.2.0] section

Validation

  • ruff check src/ tests/ — all passed
  • ruff format src/ tests/ — all formatted
  • mypy src/ — 0 issues (43 files)
  • pytest --cov=src — 46/46 passed, 80% coverage
  • C++ module builds cleanly with -Wall -Wextra, runtime verified with RGB/RGBA arrays
  • Clean Architecture dependency rule verified — no inward violations

@vladiant vladiant merged commit e36c362 into main Mar 29, 2026
7 checks passed
@vladiant vladiant deleted the minor_fixes branch March 29, 2026 18:53
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