Simplify Duration.milliseconds via the stdlib Duration ratio - #85
Merged
Conversation
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0192kxQPbqtuKYqgCzCy3Pra
There was a problem hiding this comment.
Pull request overview
This PR simplifies the engine’s Sync STT latency logging helper by leveraging Swift stdlib Duration division to compute milliseconds, removing manual recombination of Duration.components for seconds + attoseconds.
Changes:
- Replaced the manual
Duration.components-based millisecond computation withself / .milliseconds(1). - Expanded the inline documentation to explain why the ratio-based approach is preferred for this use case.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Jul 27, 2026
`Duration.milliseconds` was simplified independently on main by #83 ("Refactor non-idiomatic Swift patterns"), which made the same change this branch did: express the value as a ratio of two `Duration`s instead of reassembling it from `components`. The conflict was therefore a pure duplicate — same semantics, differing only in spelling (`self / Duration.milliseconds(1)` vs `self / .milliseconds(1)`) and comment wording. Resolved in favor of main's already-reviewed version, so this merge carries no net change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0192kxQPbqtuKYqgCzCy3Pra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thatarithmetic, so the body reduces to the ratio itself.
Behavior-identical; the two call sites are both
Logger.infolines inthe 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 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_0192kxQPbqtuKYqgCzCy3Pra