Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

perf(typing): skip redundant AX reads on the stop path

altic-dev2e0345a9b694
diff --git a/Sources/Fluid/Services/MenuBarManager.swift b/Sources/Fluid/Services/MenuBarManager.swift
index e47eaf29..8e80fb92 100644
--- a/Sources/Fluid/Services/MenuBarManager.swift
+++ b/Sources/Fluid/Services/MenuBarManager.swift
@@ -411,16 +411,18 @@ final class MenuBarManager: NSObject, ObservableObject, NSMenuDelegate {
)
self.isProcessingActive = true
NotchOverlayManager.shared.freezeForStop()
- // Log-only: lets the focused-element assessment be audited on every
- // stop, including runs whose transcript is empty and never reach typing.
- let assessStartedAt = ProcessInfo.processInfo.systemUptime
- let assessment = DeliveryTargetAssessment.assessFocusedElement()
- DebugLogger.shared.info(
- "FOCUS_ASSESS at=stop \(assessment.logDescription) " +
- "frontApp=\(NSWorkspace.shared.frontmostApplication?.bundleIdentifier ?? "nil") " +
- "elapsedUs=\(Int((ProcessInfo.processInfo.systemUptime - assessStartedAt) * 1_000_000))",
- source: "TypingService"
- )
+ // Diagnostics only: three Accessibility round-trips on the stop path
+ // are not worth paying in Release just to audit the focused element.
+ if DebugLogger.diagnosticsEnabled {
+ let assessStartedAt = ProcessInfo.processInfo.systemUptime
+ let assessment = DeliveryTargetAssessment.assessFocusedElement()
+ DebugLogger.shared.info(
+ "FOCUS_ASSESS at=stop \(assessment.logDescription) " +
+ "frontApp=\(NSWorkspace.shared.frontmostApplication?.bundleIdentifier ?? "nil") " +
+ "elapsedUs=\(Int((ProcessInfo.processInfo.systemUptime - assessStartedAt) * 1_000_000))",
+ source: "TypingService"
+ )
+ }
self.pendingProcessingShowOperation?.cancel()
self.pendingProcessingShowOperation = nil
self.pendingHideOperation?.cancel()
diff --git a/Sources/Fluid/Services/TypingService.swift b/Sources/Fluid/Services/TypingService.swift
index 6bbc8fa6..08562680 100644
--- a/Sources/Fluid/Services/TypingService.swift
+++ b/Sources/Fluid/Services/TypingService.swift
@@ -524,9 +524,11 @@ final class TypingService {
return result
}
- let verificationBefore = PasteVerifier.capture()
let usesClipboard = mode == .reliablePaste ||
self.ghosttyTargetPID(preferredTargetPID: preferredTargetPID) != nil
+ // The read-back baseline costs an AX value read; only the clipboard
+ // paths verify, so the direct path skips it.
+ var verificationBefore = usesClipboard ? PasteVerifier.capture() : nil
let result: TextDeliveryResult
let deliveryPath: AnalyticsInsertionPath
var dispatchedAt: TimeInterval?
@@ -543,6 +545,7 @@ final class TypingService {
result = .commandPosted
} else {
deliveryPath = .clipboardFallback
+ verificationBefore = PasteVerifier.capture()
self.log("[TypingService] Direct insertion failed; using non-blocking clipboard fallback")
result = await PasteDeliveryCoordinator.shared.deliver(
text,