[SR NO 22] Resolve Image Processing Performance Degradation and Memory Leaks #416
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.

Closes #351
Overview
This PR optimizes image processing performance and stability by improving the
adjust_brightness_contrastfunction and caching system. The changes resolve memory leaks, CPU bottlenecks, and inefficient cache management, significantly boosting speed and reducing resource consumption.Original Issues & Performance Bottlenecks
1️⃣ Memory Leaks
2️⃣ CPU Bottlenecks
3️⃣ Cache Inefficiencies
Optimizations & Solutions
✅ 1. Memory Leak Fixes
✔ Implemented Cache Size Limits → Prevents cache from exceeding memory constraints.
✔ LRU (Least Recently Used) Eviction Policy → Removes least-accessed images automatically.
✔ Cache Invalidation Mechanism → Removes stale entries using a Time-To-Live (TTL) policy.
✅ 2. CPU Performance Enhancements
✔ Optimized LUT Calculations → Pre-computed LUTs reduce expensive recalculations.
✔ Enabled Parallel Processing → Uses Rayon for multi-threaded execution, significantly boosting speed.
✔ Removed Redundant Pixel Operations → Cuts down unnecessary computations.
✅ 3. Improved Cache Management
✔ More Robust Cache Key Generation → Uses image dimensions, pixel data, and operation parameters to prevent collisions.
✔ Cache Size Management → Actively evicts entries when size limits are exceeded.
✔ Cache Invalidation Strategy → Ensures outdated images are removed automatically.
🚀 Performance:
You can check the benchmark results by running:
cd frontend/src-tauri/ cargo run --example benchmark_runner