← All repositories

crossmate

A collaborative crossword app for iPhone and iPad

git clone https://code.inqk.net/crossmate.git


commit eaf7bc01cfca8e1197eb40761ab97aff71582d0c
parent 04cb8edfe1ff0c032f4127ff63305ca3b5ca7ca9
Author: Michael Camilleri <[email protected]>
Date:   Tue, 26 May 2026 00:00:26 +0900

Add lag measuring instrumentation

Diffstat

MCrossmate/Services/AppServices.swift | 13+++++++++----

1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/Crossmate/Services/AppServices.swift b/Crossmate/Services/AppServices.swift

@@ -732,10 +732,12 @@ final class AppServices {
     }
 
     private func handleEngagementMessage(_ envelope: EngagementMessage, engagementID: UUID) {
+        let latencyMs = max(0, Int(Date().timeIntervalSince(envelope.sentAt) * 1000))
         switch envelope.kind {
         case .debugText:
             syncMonitor.note(
-                "engagement: received \(envelope.kind.rawValue) \(engagementID.uuidString): \(envelope.text)"
+                "engagement: received \(envelope.kind.rawValue) \(engagementID.uuidString) " +
+                "latency=\(latencyMs)ms: \(envelope.text)"
             )
         case .cellEdit:
             guard let edit = envelope.cellEdit else {
@@ -746,12 +748,14 @@ final class AppServices {
             if applied {
                 syncMonitor.note(
                     "engagement: applied cellEdit \(engagementID.uuidString) " +
-                    "r=\(edit.row) c=\(edit.col) device=\(edit.deviceID.prefix(8))"
+                    "r=\(edit.row) c=\(edit.col) device=\(edit.deviceID.prefix(8)) " +
+                    "latency=\(latencyMs)ms"
                 )
             } else {
                 syncMonitor.note(
                     "engagement: rejected cellEdit \(engagementID.uuidString) " +
-                    "r=\(edit.row) c=\(edit.col) device=\(edit.deviceID.prefix(8))"
+                    "r=\(edit.row) c=\(edit.col) device=\(edit.deviceID.prefix(8)) " +
+                    "latency=\(latencyMs)ms"
                 )
             }
         case .selection:
@@ -762,7 +766,8 @@ final class AppServices {
             engagementStore.set(selection)
             syncMonitor.note(
                 "engagement: received selection \(engagementID.uuidString) " +
-                "r=\(selection.row) c=\(selection.col) device=\(selection.deviceID.prefix(8))"
+                "r=\(selection.row) c=\(selection.col) device=\(selection.deviceID.prefix(8)) " +
+                "latency=\(latencyMs)ms"
             )
         }
     }