Skip to content

Reduce capture and diagnostics overhead - #254

Merged
jatinkrmalik merged 2 commits into
VocaHQ:mainfrom
Mr-Sunglasses:perf/runtime-latency
Sep 5, 2026
Merged

Reduce capture and diagnostics overhead#254
jatinkrmalik merged 2 commits into
VocaHQ:mainfrom
Mr-Sunglasses:perf/runtime-latency

Conversation

@Mr-Sunglasses

@Mr-Sunglasses Mr-Sunglasses commented Sep 5, 2026

Copy link
Copy Markdown
Member

Problem

Several runtime paths did avoidable work or leaked resources: capture repeatedly reserved exact array capacity and rebuilt its sample-rate converter, process monitoring leaked Mach thread send rights and continued polling while hidden, and log rotation stopped working once all backup slots existed. The active log on the audited machine had consequently grown to about 14 MB, making diagnostic reads expensive.

Changes

  • bulk-append captured samples and reuse the audio converter while the input format is stable
  • release every Mach thread right returned by task_threads and poll resource usage only while its view is visible
  • make rolling logs bounded and safe across GUI/CLI processes, repair full backup rotation, trim legacy oversized files, and read tails without loading every log into memory
  • add Instruments signposts for hotkey, recording start, model load, transcription, stop-to-result, and clipboard paste latency
  • add regressions for converter reuse, sample/mute preservation, bounded chronological log rotation, Unicode tail reads, and Mach-port cleanup

Evidence

The audit harness measured 60 seconds of capture accumulation at 21.61 ms with exact reservation/sample appends and 0.25 ms with geometric bulk append. At a 600-second stress duration it measured 7,140.10 ms versus 2.94 ms. Reusing the converter reduced a 4,096-frame conversion prototype from 0.0202 ms to 0.0114 ms per buffer. The Mach-port reproduction changed from 4 to 104 send references after 100 refreshes; the fixed form stayed at 3 to 3. Reading the existing oversized log fell from a 117.46 ms whole-file prototype to a 0.84 ms bounded-tail prototype.

These measurements are fixed-device diagnostics rather than CI thresholds. The signposts provide end-to-end evidence on representative machines without making hosted-runner timing flaky.

Validation

  • swift build
  • swift build -c release
  • swift test — 448 tests passed, 1 environment-dependent Accessibility test skipped
  • focused logger suite after the final count-path adjustment — 15 tests passed
  • current-source Tiny smoke check retained transcript correctness as a separate issue: the 0.50 s fixture remained empty, while padding it to 1.25 s produced Hello.; the direct decoder fix is in fix: recover empty short Whisper transcriptions #255
  • self-review follow-up: preserve complete log entries when trimming at an exact line boundary; discard incomplete UTF-8 entries when none fits; restrict orphan cleanup to .log files
  • 35 focused logger, audio, and process-monitor tests passed after self-review, including sample-by-sample cached/fresh converter comparisons across repeated buffers and sample-rate changes

@netlify

netlify Bot commented Sep 5, 2026

Copy link
Copy Markdown

Deploy Preview for voca-mac canceled.

Name Link
🔨 Latest commit 8785292
🔍 Latest deploy log https://app.netlify.com/projects/voca-mac/deploys/6a9b60ddfb602e000883107f

@github-actions github-actions Bot added app ci enhancement New feature or request and removed ci labels Sep 5, 2026
@greptile-apps

greptile-apps Bot commented Sep 5, 2026

Copy link
Copy Markdown

Greptile Summary

This PR reduces capture and diagnostics overhead while adding latency instrumentation.

  • Reuses stable audio converters and bulk-appends captured samples.
  • Bounds, rotates, locks, and tail-reads diagnostic logs.
  • Stops resource polling while diagnostic views are hidden and releases Mach thread rights.
  • Adds Instruments signposts and regression coverage for the optimized paths.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
Sources/VocaMac/Services/AudioEngine.swift Reuses converters for stable formats and replaces per-sample appends with a bulk operation while preserving mute behavior.
Sources/VocaMac/Services/Logger.swift Introduces locked cross-process log writes, repaired bounded rotation, legacy trimming, and bounded tail reads.
Sources/VocaMac/Views/MenuBarView.swift Limits process monitoring to the visible view lifecycle and releases Mach thread send rights after sampling.
Sources/VocaMac/Services/PerformanceTrace.swift Adds a lightweight signpost abstraction used to measure user-perceived latency intervals.
Sources/VocaMac/Services/TextInjector.swift Instruments clipboard injection through simulated paste without changing injection behavior.
Sources/VocaMac/Services/TranscriptionRouter.swift Instruments serialized model loading and transcription operations.
Tests/VocaMacTests/LoggerTests.swift Adds coverage for bounded chronological rotation, exact cutoffs, oversized files, and Unicode tail reads.
Tests/VocaMacTests/ProcessMonitorTests.swift Verifies repeated process sampling does not leak current-thread send rights.
Tests/VocaMacTests/ServiceTests.swift Verifies converter reuse and replacement along with bulk sample and mute preservation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Audio tap buffer] --> B[Reuse or replace converter]
  B --> C[Convert to Whisper format]
  C --> D[Bulk append samples]
  E[Log event] --> F[Serial file queue]
  F --> G[Cross-process file lock]
  G --> H{Rotation threshold reached?}
  H -- No --> I[Append active log]
  H -- Yes --> J[Rotate and trim backups]
  K[Resource view appears] --> L[Start process monitor]
  L --> M[Refresh every five seconds]
  M --> N[Release sampled thread rights]
  O[Resource view disappears] --> P[Stop process monitor]
Loading

Reviews (2): Last reviewed commit: "fix: preserve log trim boundaries and ve..." | Re-trigger Greptile

@jatinkrmalik

Copy link
Copy Markdown
Member

@Mr-Sunglasses thanks, this looks good. Merging.

@jatinkrmalik
jatinkrmalik merged commit 3e2a6ff into VocaHQ:main Sep 5, 2026
10 checks passed
@Mr-Sunglasses
Mr-Sunglasses deleted the perf/runtime-latency branch September 5, 2026 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants