- Phone camera native: ~1920×1080 (≈4MB JPEG raw)
- After resize to 480×480: ≈30-70KB JPEG at quality 0.82
- Bandwidth savings: ~97% reduction
- Board detection accuracy: No meaningful loss at 480px — chess squares are 60px each, plenty for colour classification.
- Quality 0.90+ → no accuracy gain, +40% file size
- Quality 0.70 → noticeable artifacts in square boundaries, reduces detection accuracy
- 0.82 is the sweet spot for phone camera over 4G
- Without persistence: each request spawns a new process = 200-400ms overhead + CPU spike
- With persistence: process kept alive, reused = 0ms spawn overhead
- Lock used:
threading.Lockguards concurrent access (FastAPI uses thread pool for sync code)
Hash: 64MB— transposition table. 256MB would be faster but risks OOM on Railway Starter ($5/mo).Threads: 2— Railway Starter has 2 vCPUs. Setting higher has no benefit.
- SHA-1 hash of the first 2KB of the base64 image
- If hash matches last frame, skip the entire detection + Stockfish pipeline
- Eliminates ~80% of redundant work during static positions
- Full FEN comparison (board part only, ignoring clocks)
- Prevents Stockfish calls when the board hasn't changed between frames
- Poll interval: 2500ms — fast enough to catch moves, slow enough not to waste data
- Per-frame upload: ~40-60KB JPEG
- Per-frame download: ~25KB (JSON with base64 board image)
- Total per move: ~100KB — negligible on 4G
| Resource | Idle | During analysis |
|---|---|---|
| CPU | ~1% | ~15-25% |
| RAM | ~80MB | ~120MB |
| Network | 0 | ~100KB/move |
Fits comfortably in Railway Starter plan ($5/mo).
-
WebSocket instead of HTTP polling
- Eliminates HTTP handshake overhead (~20ms saved per frame)
- Use if latency becomes noticeable in fast bullet games
-
YOLOv8 piece detection
- Would improve piece-type classification (currently all pieces shown as pawns in FEN)
- Add
ultralyticsto requirements, downloadyolov8n-chess.pt(~6MB) - Trade-off: +100ms inference on CPU, +200MB RAM
-
Frontend PWA
- Add
manifest.jsonand service worker for home screen install on Android - Enables offline caching of static assets
- Add
-
Rate limit tuning
- Current: 1s minimum between requests per session
- Reduce to 0.5s for faster capture during fast games