Skip to content

Optimize word of day fallback to single Swift invocation#5

Merged
bgreg merged 4 commits into
fix/weather-and-word-of-day-improvementsfrom
copilot/sub-pr-1-yet-again
Dec 22, 2025
Merged

Optimize word of day fallback to single Swift invocation#5
bgreg merged 4 commits into
fix/weather-and-word-of-day-improvementsfrom
copilot/sub-pr-1-yet-again

Conversation

Copilot AI commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

The fallback mechanism was invoking Swift 5 times in a loop (once per fallback word), incurring startup overhead of 100-300ms per invocation—up to 1.5s in worst case.

Changes:

  • Consolidated fallback word lookup into single Swift invocation that iterates internally
  • Swift returns first successful match with both word and definition
  • Reduced worst-case overhead from 1-2s to ~100-300ms (5x improvement)

Implementation:

// Before: Shell loop with 5 separate Swift invocations
for fallback in "ephemeral" "serendipity" "eloquent" "resilient" "catalyst"; do
  definition=$(swift -e '...' -- "$fallback")
  [[ -n "$definition" ]] && word="$fallback" && break
done

// After: Single Swift invocation with internal iteration
fallback_result=$(swift -e '
let fallbackWords = ["ephemeral", "serendipity", "eloquent", "resilient", "catalyst"]
for word in fallbackWords {
    if let def = DCSCopyTextDefinition(...) {
        print(word)
        print("<<<DEFINITION_DELIMITER>>>")
        print(def)
        break
    }
}
')

Shell parsing uses delimiter-based awk patterns with explicit state tracking for robustness.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits December 22, 2025 22:51
Co-authored-by: bgreg <3711139+bgreg@users.noreply.github.com>
Co-authored-by: bgreg <3711139+bgreg@users.noreply.github.com>
Co-authored-by: bgreg <3711139+bgreg@users.noreply.github.com>
Copilot AI changed the title [WIP] Update weather geolocation and offline word of day fix Optimize word of day fallback to single Swift invocation Dec 22, 2025
Copilot AI requested a review from bgreg December 22, 2025 22:54
@bgreg bgreg marked this pull request as ready for review December 22, 2025 23:02
@bgreg bgreg merged commit b30bc30 into fix/weather-and-word-of-day-improvements Dec 22, 2025
bgreg added a commit that referenced this pull request Mar 31, 2026
Optimize word of day fallback to single Swift invocation
bgreg added a commit that referenced this pull request Jun 30, 2026
Optimize word of day fallback to single Swift invocation
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.

2 participants