onUpdate for GLANCE view fires way too often on my real device

As I was trying to figure out the memory consumption for Storage.SetValue, I came around another weird behavior that happens only on my real device this time, not the simulator

I've added a println at the start of the GlanceView onUpdate function that displayed the free memory. The println also prints the current time. The onUpdate is triggered by a Ui.requestUpdate in a timer that fires every FIVE seconds (mTimer.start(method(:onRefreshTimer), 5000, true)). I've also added a println in that onRefreshTimer just before that requestUpdate line (as well as in every function with the :glance label that calls requestUpdate so I would know which one triggers it). This is what the simulator shows and is expected.

Every requestUpdate from the timer is followed by a 'Free memory...' line.

21:41:28 : onRefreshTimer requestUpdate
21:41:28 : Free memory 36 KB
21:41:33 : onRefreshTimer requestUpdate
21:41:33 : Free memory 36 KB
21:41:38 : onRefreshTimer requestUpdate
21:41:38 : Free memory 36 KB
21:41:43 : onRefreshTimer requestUpdate
21:41:43 : Free memory 36 KB

Now compare this to what I see on my device:

21:46:47 : Free memory 37 KB
21:46:48 : Free memory 37 KB
21:46:48 : Free memory 37 KB
21:46:49 : Free memory 37 KB
21:46:50 : Free memory 37 KB
21:46:51 : Free memory 37 KB
21:46:52 : onRefreshTimer requestUpdate
21:46:52 : Free memory 37 KB
21:46:54 : Free memory 37 KB
21:46:54 : Free memory 37 KB
21:46:55 : Free memory 37 KB
21:46:56 : Free memory 37 KB
21:46:56 : Free memory 37 KB
21:46:57 : Free memory 37 KB
21:46:57 : onRefreshTimer requestUpdate
21:46:57 : Free memory 37 KB
21:46:59 : Free memory 37 KB
21:47:00 : Free memory 37 KB
21:47:01 : Free memory 37 KB
21:47:02 : Free memory 37 KB
21:47:02 : onRefreshTimer requestUpdate
21:47:02 : Free memory 37 KB
21:47:04 : Free memory 37 KB

Why is onUpdate being ran so frequently on my device (Fenix 7S Pro)?!?

  • onUpdate is called not only when you request it, but also when the system feels it needs to. It's not clear what did you do at the time of these logs, but the docs for onUpdate has this sentence:

    • More than one call to onUpdate() may occur during View transitions

    So one possibility is that you were sliding the glances up/down. Does this also happen when you slide your glance to be in the middle of the screen and then you don't touch the screen/buttons for 20 seconds?

  • Make sure you read and understand this in the doc.  In general, you just want to system to manage when onUpdate is called.

    https://developer.garmin.com/connect-iq/core-topics/glances/

  • So one possibility is that you were sliding the glances up/down

    Yeah this was my guess, too.

    As an analogy, iirc onShow() is (unexpectedly) called several times when you scroll away from a watchface or data field, too

  • too.

    In general, you just want to system to manage when onUpdate is called.

    What you're saying makes sense if the glance does not have any live data that is frequently updated.

    You may be making that assumption based on OP saying they call requestUpdate once every 5 seconds, and you may be right. If there's no new data to be displayed, then there's no reason to call requestUpdate.

    Otoh, if you want your glance to support live updates (assuming the hardware support is present), you need to call requestUpdate yourself.

    From the docs you linked:

    Live UI Update

    Devices that have ample resources 1 will start the Widget in Glance mode, and keep it alive. The provided WatchUi.GlanceView will be updated as needed by the system, and calls to WatchUi.requestUpdate() will trigger a WatchUi.View update as expected.

    The live glance feature wouldn't make any sense if the dev was not supposed to call requestUpdate. And the docs wouldn't literally say "calls to WatchUi.requestUpdate() will trigger a WatchUi.View update as expected."

    As an example, the built-in music glance will update about once per second if music is playing, to reflect the current position in the song. As another example, the HR glance updates about once per second. Ofc I am referring to the glance views themselves, not the main view that you get when you "open" the glance.

    If you were to build a CIQ app that also has some kind of live updates in the glance, the system wouldn't automatically know that the glance wants to update once per second - when possible. The app would have to call requestUpdate() itself.

  • Just tried it again. I scrolled from the watch face to the Glances and let it stand. This is what the log showed. Maybe the first few seconds is while the glance came into view, but after that? It simply was showing still. 

    15:53:42 : Free memory 37 KB
    15:53:42 : Free memory 37 KB
    15:53:43 : Free memory 37 KB
    15:53:44 : Free memory 37 KB
    15:53:45 : Free memory 37 KB
    15:53:46 : Free memory 37 KB
    15:53:47 : onRefreshTimer requestUpdate
    15:53:47 : Free memory 37 KB
    15:53:48 : Free memory 37 KB
    15:53:49 : Free memory 37 KB
    15:53:49 : Free memory 37 KB
    15:53:49 : Free memory 37 KB
    15:53:50 : Free memory 37 KB
    15:53:51 : Free memory 37 KB
    15:53:52 : onRefreshTimer requestUpdate
    15:53:52 : Free memory 37 KB
    15:53:53 : Free memory 37 KB
    15:53:53 : Free memory 37 KB
    15:53:54 : Free memory 37 KB

  • If you wait long enough, do the updates ever slow down "permanently"? The "fast" updates seem kind of intermittent in your examples. Perhaps because you are also calling requestUpdate.

    What if you remove your calls to requestUpdate - what do the updates look like then?

  • "As an example, the built-in music glance will update about once per second if music is playing, to reflect the current position in the song. As another example, the HR glance updates about once per second. Ofc I am referring to the glance views themselves, not the main view that you get when you "open" the glance"

    I have a few apps that implement text scrolling in the Glance view using a 50 msec timer, but this app isn't one of them. Between those 5 second, nothing happns. I don't get why onUpdate is called that often when nothing is happening and the watch isn't been interacted with. I just checked my Edge 840 and it doesn't behave that way

    16:12:16 : onRefreshTimer requestUpdate
    16:12:16 : Free memory 37 KB
    16:12:16 : Free memory 37 KB
    16:12:21 : onRefreshTimer requestUpdate
    16:12:21 : Free memory 37 KB
    16:12:26 : onRefreshTimer requestUpdate
    16:12:26 : Free memory 37 KB
    16:12:31 : onRefreshTimer requestUpdate
    16:12:31 : Free memory 37 KB
    16:12:36 : onRefreshTimer: Charging [1755979956, 450, null]
    16:12:36 : onRefreshTimer requestUpdate
    16:12:36 : Free memory 37 KB
    16:12:41 : onRefreshTimer: Charging [1755979961, 450, null]
    16:12:41 : onRefreshTimer requestUpdate
    16:12:41 : Free memory 37 KB

    The double 'Free memory' at start I presumed is after I booted up the Edge (the app glance is visible on the main page). The last two with the added 'Charging' line is after I plugged the Edge on my computer to retrieve the log.

  • This is the log for 30 seconds of sitting still with the Ui.updateRequest() commented out in the timer function.

    16:24:49 : Free memory 37 KB
    16:24:50 : Free memory 37 KB
    16:24:51 : Free memory 37 KB
    16:24:52 : Free memory 37 KB
    16:24:53 : Free memory 37 KB
    16:24:54 : onRefreshTimer requestUpdate NOT called
    16:24:54 : Free memory 37 KB
    16:24:56 : Free memory 37 KB
    16:24:56 : Free memory 37 KB
    16:24:56 : Free memory 37 KB
    16:24:57 : Free memory 37 KB
    16:24:58 : Free memory 37 KB
    16:24:59 : onRefreshTimer requestUpdate NOT called
    16:24:59 : Free memory 37 KB
    16:25:01 : Free memory 37 KB
    16:25:02 : Free memory 37 KB
    16:25:03 : Free memory 37 KB
    16:25:04 : onRefreshTimer requestUpdate NOT called
    16:25:04 : Free memory 37 KB
    16:25:06 : Free memory 37 KB
    16:25:07 : Free memory 37 KB
    16:25:08 : Free memory 37 KB
    16:25:09 : onRefreshTimer requestUpdate NOT called
    16:25:09 : Free memory 37 KB
    16:25:11 : Free memory 37 KB
    16:25:12 : Free memory 37 KB
    16:25:13 : Free memory 37 KB
    16:25:14 : onRefreshTimer requestUpdate NOT called
    16:25:14 : Free memory 37 KB
    16:25:16 : Free memory 37 KB
    16:25:17 : Free memory 37 KB
    16:25:18 : Free memory 37 KB
    16:25:19 : onRefreshTimer requestUpdate NOT called
    16:25:19 : Free memory 37 KB
    16:25:20 : Free memory 37 KB
    16:25:21 : Free memory 37 KB
    16:25:22 : Free memory 37 KB
    16:25:23 : Free memory 37 KB
    16:25:23 : Free memory 37 KB
    16:25:24 : Free memory 37 KB

  • Seems like it's mostly once per second with a few spikes.

    Idk, maybe Garmin decided to be nice and updates glances once per second regardless of developer intent. Maybe there were some CIQ glances whose display would be broken if they didn't do this?

    Maybe it has something to do with how native glances are updated?

    I have no clue tbh.