Problem: calculateConfidenceAndRecordHistory() called on every view render
Solution:
- Add
@Published deviceConfidenceCacheto NetworkDiscoveryManager - Calculate confidence once when device is added
- Views read from cache only
- Update cache when device data changes
Problem: discoveredDevices array grows unbounded
Solution:
- Add
maxDevices = 500constant - Implement LRU eviction when limit reached
- Evict oldest discovered devices first
Problem: Opening NWConnection for every device just to get IP Solution:
- Extract host/port from NWBrowser.Result.endpoint directly
- Remove wasteful connection creation
- Keep fallback timeout for edge cases
Problem: Connection handler captures connection strongly Solution:
- Change to
[weak self, weak connection]in all handlers - Prevent memory leaks
Problem: filteredDevices recomputed on every render
Solution:
- Move to ViewModel with cached result
- Invalidate cache only on actual data changes
- Added deviceConfidenceCache to NetworkDiscoveryManager
- Added maxDevices constant
- Implement addDevice() helper with caching and bounds
- Fix NWConnection retain cycles
- Implement LRU eviction for bounded arrays
- Update DeviceCardView to use cache
- Fix tuple naming issue in getCachedConfidence
- Add NetworkDiscoveryManagerTests (14 tests)
- Add SecureStorageManagerTests (25 tests)
- Add InputValidatorTests (45 tests)
- Add LoggingManagerTests (30 tests)
- Remove wasteful connection creation (OPTIONAL)
- Create ScannerViewModel (OPTIONAL)
- Add remaining 4 test files
- Run all tests and verify coverage