From 60dadf8fd32f5bb9fc217f1b4ad935ebdfca06f7 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 27 Jul 2026 19:31:29 +0000 Subject: [PATCH] Simplify Duration.milliseconds via the stdlib Duration ratio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The latency-logging helper hand-derived milliseconds from `components`, recombining seconds and attoseconds by hand. The stdlib's `Duration / Duration -> Double` (SE-0329) performs exactly that arithmetic, so the body reduces to the ratio itself. Behavior-identical; the two call sites are both `Logger.info` lines in the Sync round-trip instrumentation. Found while auditing the codebase for external Swift libraries that could simplify it. That audit came back empty by design — the engine is dependency-free by rule (enforced by check.sh's no-external-dependencies guard), and every candidate evaluated (Defaults, KeychainAccess, Alamofire/MultipartKit, swift-async-algorithms, swift-clocks, AXSwift) would either lose documented semantics or replace less code than it adds. This was the one genuine simplification, and it needs no library. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_0192kxQPbqtuKYqgCzCy3Pra --- Sources/BlurtEngine/STT/AssemblyAITranscriber.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/BlurtEngine/STT/AssemblyAITranscriber.swift b/Sources/BlurtEngine/STT/AssemblyAITranscriber.swift index 8e12a8a..15ba9f2 100644 --- a/Sources/BlurtEngine/STT/AssemblyAITranscriber.swift +++ b/Sources/BlurtEngine/STT/AssemblyAITranscriber.swift @@ -262,10 +262,12 @@ private final class MetricsLogger: NSObject, URLSessionTaskDelegate, @unchecked } extension Duration { - /// This duration in milliseconds as a Double (for latency logging). + /// This duration in milliseconds as a Double (for latency logging). The + /// stdlib's `Duration / Duration -> Double` (SE-0329) does the seconds + + /// attoseconds arithmetic exactly, so expressing the ratio directly beats + /// re-deriving it from `components`. fileprivate var milliseconds: Double { - let c = components - return Double(c.seconds) * 1000 + Double(c.attoseconds) / 1_000_000_000_000_000 + self / .milliseconds(1) } }