perf(Telemetry): defer play/stop SD writes off the command path (F-075, v2.4.1)

recordPlayback() and saveStrikeCounters() wrote JSON to SD inline in the
async_tcp task, before playback.play/stop could send their reply. They now
set a pending flag and notify TelemetryTask, which writes within ms. The
task's periodic work keeps its 1 s cadence (checkBellLoads decays per call);
pending writes are held during the OTA pause. Verified on hardware: the reply
now goes out before the SD write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-15 22:27:31 +03:00
co-authored by Claude Opus 5.5
parent b121560b1f
commit 290445e3ad
4 changed files with 30 additions and 2 deletions
+17
View File
@@ -87,6 +87,7 @@ Check `git log -- src/Version.hpp` for the real bump history before tagging a ne
| F-072 | Lower status/reply latency — QoS 0 for non-critical MQTT topics; WiFi modem sleep disabled | v2.4.0 | Stable |
| F-073 | Confirmed delivery for `status/playback` + `control/reports` (QoS 1, PUBACK tracked, reset + republish/resend); AsyncMqttClient vendored + patched; all dependencies pinned | v2.4.0 | Stable |
| F-074 | Fix: `mode: "infinite"` no longer flips status playing/paused every ~0.5 s | v2.4.0 | Stable |
| F-075 | Play/stop command replies no longer wait for telemetry SD writes (deferred to TelemetryTask) | v2.4.1 | Stable |
---
@@ -1549,3 +1550,19 @@ checked `continuous_loop`, so with a 0 ms segment every duration-timer tick paus
rejects `duration: 0`, so no valid segmented mode is affected.
Subsystem: `src/Player/Player.cpp`
### F-075 — Telemetry SD writes deferred off the command path
**Symptom.** Measured on hardware (2026-10-15): the `playback.play`/`playback.stop` reply arrived 50–100 ms
after the status broadcast even with serial logging off. Between the two, the command handler wrote to the SD
card: `Telemetry::recordPlayback()` (play → `/telemetry_runtime.json`) and `saveStrikeCounters()` (stop →
`/telemetry_data.json`), both inline in the async_tcp task that also has to send the reply.
**Change.** Both now set a pending flag and notify `TelemetryTask`, which does the write within milliseconds
(`processPendingSaves()`). The task waits on a notification instead of a plain 1 s delay, but the periodic
work keeps its 1 s cadence, since `checkBellLoads()` decays bell loads once per call. Pending writes are
held while telemetry is paused for OTA and done right after `resume()`. Before the task exists (early boot)
`saveStrikeCounters()` still writes synchronously. Repeated requests before the write happens collapse into
one write of the latest values.
Subsystem: `src/Telemetry/Telemetry.hpp`, `src/Telemetry/Telemetry.cpp`
Binary file not shown.
+11 -1
View File
@@ -192,7 +192,10 @@ public:
uint32_t getStrikeCount(uint8_t bellIndex);
void resetStrikeCounters(); // User-requested reset (per bell or all)
// Persistence methods
// Persistence methods.
// saveStrikeCounters() only *requests* the SD write; TelemetryTask does it
// within a few ms. Player calls this on stop, inside the command handler —
// an inline SD write held the command reply back by 50-100 ms (F-075).
void saveStrikeCounters();
void loadStrikeCounters();
@@ -314,6 +317,13 @@ private:
void checkBellLoads();
void loadMetrics();
void saveMetrics();
void writeStrikeCountersNow();
// Deferred SD writes, set from any task, done by TelemetryTask (F-075)
volatile bool _strikeSavePending = false;
volatile bool _metricsSavePending = false;
TaskHandle_t telemetryTaskHandleForNotify() const;
void processPendingSaves();
};
#endif
+2 -1
View File
@@ -28,8 +28,9 @@
// mqtt.status, confirmed QoS 1 for playback/reports (QoS 0 elsewhere),
// WiFi modem sleep off, vendored/patched AsyncMqttClient, pinned deps,
// WiFi/NTP task-retry, infinite-mode status flicker fix (F-071..F-074)
// v2.4.1 - Play/stop replies no longer wait for telemetry SD writes (F-075)
// ═══════════════════════════════════════════════════════════════════════
#define FW_VERSION "2.4.0"
#define FW_VERSION "2.4.1"
// ═══════════════════════════════════════════════════════════════════════
// SemVer — lightweight 3-part version struct