Skip to content

Latest commit

 

History

History
55 lines (47 loc) · 1.94 KB

File metadata and controls

55 lines (47 loc) · 1.94 KB

Performance Optimization Implementation Log

Critical Fixes Being Applied

Fix #1: DeviceCardView Side Effects

Problem: calculateConfidenceAndRecordHistory() called on every view render Solution:

  • Add @Published deviceConfidenceCache to NetworkDiscoveryManager
  • Calculate confidence once when device is added
  • Views read from cache only
  • Update cache when device data changes

Fix #2: Bounded Device Array

Problem: discoveredDevices array grows unbounded Solution:

  • Add maxDevices = 500 constant
  • Implement LRU eviction when limit reached
  • Evict oldest discovered devices first

Fix #3: Network Connection Optimization

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

Fix #4: Retain Cycle in NWConnection

Problem: Connection handler captures connection strongly Solution:

  • Change to [weak self, weak connection] in all handlers
  • Prevent memory leaks

Fix #5: ScannerView Filter Performance

Problem: filteredDevices recomputed on every render Solution:

  • Move to ViewModel with cached result
  • Invalidate cache only on actual data changes

Implementation Status

  • 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