Skip to content

Optimize watch managers to skip processing when no watch is connected #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

marv-out
Copy link
Contributor

Watch Manager Optimizations

This PR improves app performance by preventing unnecessary processing when no watch is connected. It addresses two key issues:

Apple Watch & Garmin Watch Optimizations

Problem

The app was previously creating tasks and performing expensive calculations for watch data even when no watch was connected or the watch app wasn't installed.

Solution

  1. Added early-return guards in both watch managers:

    • BaseWatchManager.setupWatchState now checks if a watch is paired, the session is reachable and the app is installed
    • BaseGarminManager.setupGarminWatchState now checks if any Garmin devices are connected
  2. Optimized CoreData publishers to prevent task creation:

    • Added watch connectivity checks in all publisher callbacks
    • Tasks are only created when watches are actually connected
    • Added debug logs to indicate when processing is skipped

Performance Impact

These changes can potentially reduce CPU and memory usage when no watch is connected, as the app no longer:

  • Creates unnecessary background tasks
  • Performs expensive CoreData fetches
  • Builds watch state objects that would never be sent

TODO

  • Verifying that watch functionality works normally when watches are connected
  • Confirmed that unnecessary processing is skipped when no watch is connected
  • Testing both Apple Watch and Garmin devices

- Add connectivity checks in setupWatchState and setupGarminWatchState
- Prevent unnecessary task creation in CoreData publishers when no watch is paired
@dnzxy
Copy link
Contributor

dnzxy commented Jun 23, 2025

@t1dude (Apple watch), @mountrcg (Garmin), you both are avid watch users. Could you please give this a test, especially you @t1dude and see that this does no longer do any calls and updates to the watch manager, while keeping functionality (and especially sync after staleness) intact.

@t1dude
Copy link
Contributor

t1dude commented Jun 27, 2025

...testing in vivo for a few days.

@t1dude
Copy link
Contributor

t1dude commented Jun 27, 2025

Unfortunately, a bug in Watch OS 26 Beta 2 is preventing me from using the Trio watch app properly. I'll test this PR again once the Watch OS bug has been fixed, as the error is not related to this PR.

@mountrcg
Copy link
Contributor

Will test tomorrow!

@mountrcg
Copy link
Contributor

mountrcg commented Jun 28, 2025

No issues with garmin watch so far, running 14hrs reliably atm.

@mountrcg
Copy link
Contributor

mountrcg commented Jul 1, 2025

still on it, garmin watch is still rocksolid - go from my side

@marv-out
Copy link
Contributor Author

marv-out commented Jul 2, 2025

Ok. So we still need to confirm that apple watch works properly when connected without any dropouts. This was @dnzxy worry from looking at the guards

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.

4 participants