Skip to content

Simplify Duration.milliseconds via the stdlib Duration ratio - #85

Merged
alexkroman merged 2 commits into
mainfrom
claude/swift-libraries-audit-vz4i8s
Jul 27, 2026
Merged

Simplify Duration.milliseconds via the stdlib Duration ratio#85
alexkroman merged 2 commits into
mainfrom
claude/swift-libraries-audit-vz4i8s

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

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

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
Copilot AI review requested due to automatic review settings July 27, 2026 19:35
@alexkroman
alexkroman enabled auto-merge July 27, 2026 19:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with self / .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.

@alexkroman
alexkroman added this pull request to the merge queue Jul 27, 2026
@github-merge-queue
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
Copilot AI review requested due to automatic review settings July 27, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@alexkroman
alexkroman added this pull request to the merge queue Jul 27, 2026
Merged via the queue into main with commit fb3679c Jul 27, 2026
4 checks passed
@alexkroman
alexkroman deleted the claude/swift-libraries-audit-vz4i8s branch July 27, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants