Skip to content

Quality & Performance improvements: error handling, speed optimization, peer discovery, battery optimization#12

Merged
jpcottin merged 1 commit into
masterfrom
feature/quality-performance
May 31, 2026
Merged

Quality & Performance improvements: error handling, speed optimization, peer discovery, battery optimization#12
jpcottin merged 1 commit into
masterfrom
feature/quality-performance

Conversation

@jpcottin

Copy link
Copy Markdown
Owner

Summary

Comprehensive Quality & Performance improvements addressing four key pillars:

  1. Better Error Handling — Network timeouts, tracker/torrent error alerts, per-torrent error display, snackbar feedback for addMagnet failures
  2. Download Speed Optimization — Connection limits, unchoke slots, active torrent limits, send buffer tuning
  3. Improved Peer Discovery — DHT bootstrap nodes configured, announce_to_all_trackers/tiers enabled
  4. Battery & Memory Optimization — Adaptive tick interval (500ms foreground / 2000ms background), polling rate adjustment, alert queue capping

Technical Details

JNI (torrent_jni.cpp)

  • Added timeouts: peer 60s, request 20s, handshake 10s
  • Connection limits: 200 total, 8 unchoke slots, 4 active downloads, 4 active seeds
  • Send buffer tuning: 512KB watermark, 128KB low watermark
  • DHT bootstrap nodes: router.bittorrent.com, router.utorrent.com, dht.transmissionbt.com
  • Alert processing: collect torrent/tracker errors into per-torrent lastError field
  • Tick interval: 500ms (configurable via nativeSetTickInterval)

Kotlin Layer

  • TorrentManager: added lastError field, isInBackground flag, JNI declarations
  • DataRepository: retryWhen with exponential backoff, flowOn(IO), adaptive polling delay
  • MainActivity: lifecycle-aware tick interval control (onStart/onStop)
  • MainScreenViewModel: errorEvents SharedFlow for snackbar feedback

UI

  • MainScreen: error display on torrent cards (red text, truncated), snackbar alerts
  • All error paths now surface to user instead of silent failures

Testing & Docs

  • Added error handling test to MainScreenViewModelTest
  • All 26 unit tests pass, lint clean
  • README updated with Recent Improvements section

Verification

  • ./gradlew testDebugUnitTest — all 26 tests pass
  • ./gradlew lint — no warnings
  • ✅ App installs and launches on R37 and MP36 emulators
  • ✅ Add valid torrent — downloads normally
  • ✅ Add invalid magnet — snackbar error appears
  • ✅ Check torrent with bad tracker — lastError text on card
  • ✅ Background app → verify tick_interval slows to 2000ms
  • ✅ Foreground app → verify tick_interval restores to 500ms

…ptimization, peer discovery, battery optimization

- Better error handling: Add network timeouts (peer 60s, request 20s, handshake 10s), tracker/torrent error alerts, per-torrent lastError field displayed on cards, snackbar feedback for addMagnet failures
- Download speed: Connection limits (200 total, 8 unchoke slots), active torrent limits (4 down, 4 seed, 6 active), send buffer tuning (512KB watermark)
- Peer discovery: DHT bootstrap nodes configured, announce_to_all_trackers/tiers enabled
- Battery optimization: Adaptive tick interval (500ms foreground, 2000ms background), polling rate (3s foreground, 10s background), alert queue capped at 1000
- Code quality: Polling on IO thread, retryWhen with exponential backoff for flow resilience
- Tests: Added error handling test to MainScreenViewModelTest; all 26 tests pass
- Documentation: Updated README with Recent Improvements section

Tested on R37 and MP36 emulators - app launches and runs correctly.
@jpcottin jpcottin merged commit 1a2ee97 into master May 31, 2026
4 checks passed
@jpcottin jpcottin deleted the feature/quality-performance branch May 31, 2026 06:46
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