Possible performance issue.

Hi. guys. I'm working on settings for watchface.

To implement settings inside of function onUpdate I assigned value to variable like this

dataFields = [
    new dataLabel(steps, Mon.getInfo().steps),
    new dataLabel(beatsPerMinute, Activity.getActivityInfo().currentHeartRate),
    new dataLabel(floors, Mon.getInfo().floorsClimbed),
    new dataLabel(metres, Activity.getActivityInfo().altitude),
    new dataLabel(breath, Mon.getInfo().respirationRate),
    // new dataLabel("bb", SensorHistory.getBodyBatteryHistory()),
    new dataLabel(saturation, Activity.getActivityInfo().currentOxygenSaturation),
    // new dataLabel("Stress", SensorHistory.getStressHistory()),
    new dataLabel(energyExpenditure, Activity.getActivityInfo().energyExpenditure),
    new dataLabel(recovery, Mon.getInfo().timeToRecovery),
    new dataLabel(metres, Mon.getInfo().distance * 100),
    new dataLabel(activity, Mon.getInfo().activeMinutesDay.total),
];

After user change settings I get values from this array by index like this dataFields[settingValue] it works fine, but I have some doubts about performance.

In array I have 10 values, but only 4 of them are displayed by watchface. So the question is will all other (inactive) array elements update in background? If so how can I avoid this?

  • First, you can reduce the number of API calls:

    var info = Mon.getInfo();
    var activityInfo = Activity.getActivityInfo();
    dataFields = [
        new dataLabel(steps, info.steps),
        new dataLabel(beatsPerMinute, activityInfo.currentHeartRate),
    ...

    Next, I'd try to only keep those objects in the array that are actually required.