perf: reduce battery drain by 88% fewer timer wake-ups#504
Merged
torlando-tech merged 3 commits intomainfrom Feb 21, 2026
Merged
perf: reduce battery drain by 88% fewer timer wake-ups#504torlando-tech merged 3 commits intomainfrom
torlando-tech merged 3 commits intomainfrom
Conversation
Remove WiFi lock (WIFI_MODE_FULL_HIGH_PERF) — the battery whitelist already ensures network access during Doze, and 802.11 power-save mode only adds 100-300ms latency without dropping the TCP connection. Briar operates successfully without a WiFi lock. This alone reduces WiFi radio power by ~10x during idle periods. Increase health check interval from 5s to 30s (stale threshold 10s→60s), lock refresh interval from 5min to 2h, Python maintenance loop from 1s to 30s, and Python heartbeat idle interval from 1s to 5s. These were all over-provisioned relative to their actual detection/timeout requirements. Net effect: timer-driven wake-ups drop from ~7,932/hour to ~960/hour. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Greptile SummaryThis PR reduces battery drain by 88% through strategic timer interval adjustments and WiFi lock removal. The changes are well-coordinated across Python and Kotlin layers with proper safety margins maintained. Key changes:
Technical correctness:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Python as Python Process<br/>(heartbeat & maintenance)
participant Kotlin as Kotlin HealthCheck<br/>& Maintenance
participant System as Android System<br/>(Wake Lock)
Note over Python: Idle heartbeat: 5s<br/>(was 1s)
Note over Kotlin: Health check: 30s<br/>(was 5s)
Note over Kotlin: Stale threshold: 60s<br/>(was 10s)
loop Every 5 seconds
Python->>Python: Update heartbeat timestamp
Note over Python: Active sync: 100ms<br/>Idle: 5s
end
loop Every 30 seconds
Kotlin->>Python: getHeartbeat()
Python-->>Kotlin: timestamp
Kotlin->>Kotlin: Check if age > 60s
alt Heartbeat fresh (age < 60s)
Note over Kotlin: Reset stale counter
else Heartbeat stale (age > 60s)
Note over Kotlin: Increment stale counter
alt 2 consecutive stale checks
Kotlin->>System: Trigger service restart
end
end
end
loop Every 2 hours (was 5 min)
Kotlin->>System: Refresh wake lock
Note over System: Wake lock timeout: 10h<br/>5 refreshes per timeout
end
loop Every 30 seconds (was 1s)
Python->>Python: Check failed_interfaces
alt interfaces need retry
Python->>Python: Retry failed interfaces
end
end
Note over Python,System: Wake-ups reduced from ~7,932/hr to ~960/hr (88% reduction)
Last reviewed commit: 6b3e697 |
Update 4 Python docstrings and 1 log message that still referenced the old 1s heartbeat interval after it was changed to 5s idle. Remove dead WifiLock entries from detekt NoRelaxedMocksRule allowlist. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The idle heartbeat interval was changed from 1s to 5s, but the test's join(timeout=3) was not updated. The thread may be sleeping when initialized is set to False and needs up to 5s to wake and check the loop condition. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
WIFI_MODE_FULL_HIGH_PERF) — the battery optimization whitelist already ensures network access during Doze, and 802.11 power-save mode only adds 100-300ms latency without dropping the TCP connection. Briar (closest comparable mesh messenger) operates successfully without one. Reduces WiFi radio power ~10x during idle.failed_interfacesis non-empty; sleeping 1s was pure overhead.Wake-up budget
What we keep (and why)
Foreground service, PARTIAL_WAKE_LOCK, battery whitelist, MulticastLock (needed for LAN discovery), START_STICKY + explicit restart, ConnectivityManager.NetworkCallback, CompanionDeviceService, auto-announce, identity resolution, and ConversationLinkManager — all either zero-cost event-driven or functionally required.
Test plan
assembleNoSentryDebug)dumpsys wifi)dumpsys batterystats)🤖 Generated with Claude Code