house-of-abbey / GarminHomeAssistant

Garmin application to provide a dashboard to control your Home Assistant
https://community.home-assistant.io/t/home-assistant-app-for-garmin/637348
MIT License
101 stars 14 forks source link

Reduce startup delay #31

Closed minusnine closed 9 months ago

minusnine commented 10 months ago

While I'm on my bike, I'd like to be able to press a few buttons on my watch without looking to open the garage door. However, there is sometimes a several second delay between launching the HomeAssistant app and the menu rendering, and this delay is variable.

I believe this is because the app performs a synchronous HTTP GET to retrieve the configuration.

My configuration is currently stored in Home Assistant's web server, accessed via Nabu Casa. While I suppose I could deploy some edge caching to speed up the Internet part of this operation, this seems less optimal than caching the configuration within the app itself. Of course, with caching comes the cache invalidation problem.

Would you consider some means to allow the user to cache this information to reduce latency?

One idea would be to require the user to explicitly refresh the configuration via an App-provided menu item on the watch. This might be opt-in and enabled only if the user has made a configuration setting through ConnectIQ to disable prefetching.

Another idea would be to add this into the user-provided JSON configuration, such that on subsequent launches, the configuration file is not refreshed automatically, only on-demand.

An extension of this idea would be to add -- in addition to menu item for manual use -- a background, periodic callback to refresh the configuration every N minutes, for some N.

philipabbey commented 10 months ago

Hello @minusnine!

Thank you for your interest in the application.

I believe this is because the app performs a synchronous HTTP GET to retrieve the configuration.

All responses to a call to makeWebRequest are asynchronous, meaning once they are fired off, the application continues, but it can't do much without the response!

Would you consider some means to allow the user to cache this information to reduce latency?

Under different circumstances - yes. However we are limited in what we can offer in a watch environment. Presently, I'm trying desparately to reduce the memory footprint in order to continue supporting some older devices. As a result there will be no room for new features.

Sorry.

philipabbey commented 10 months ago

Might trial this to see if it saves a noticeable amount of time given the toggle states still need updating anyway.

philipabbey commented 10 months ago

Simulation of a Vivoactive 3 device without debug:

Error: Out Of Memory Error
Details: Failed invoking <symbol>
Stack: 
  - initialize() at 

Encountered app crash.

Pity as I had it working quite nicely.

philipabbey commented 10 months ago

So the memory issues might just be down to struggling to force the SDK to compile without debug.

minusnine commented 9 months ago

@philipabbey Thank you very much!