Skip to content

Optimize FFI bridge serialization and move blocking Swift FFI calls to background#12

Open
Maloron wants to merge 1 commit into
b-nnett:mainfrom
Maloron:perf/ffi-background-threading
Open

Optimize FFI bridge serialization and move blocking Swift FFI calls to background#12
Maloron wants to merge 1 commit into
b-nnett:mainfrom
Maloron:perf/ffi-background-threading

Conversation

@Maloron

@Maloron Maloron commented Jun 3, 2026

Copy link
Copy Markdown

Summary

This PR addresses performance bottlenecks and UI stuttering/freezes in the iOS application by optimizing FFI boundary serialization and moving synchronous Rust bridge calls off the main thread.

Key Changes

  1. Optimized FFI JSON Payloads (Rust):

    • Added an optional include_result flag to ParseFrameBatchArgs in bridge.rs.
    • When set to false (e.g., during packet sync), the bridge skips serializing the massive detailed JSON structures for each parsed frame. This dramatically reduces the FFI string payload size.
  2. Background Threading (Swift):

    • Offloaded blocking synchronous FFI calls in refreshBridgeCatalogs(), runPacketScores(), and runSleepScore() from the @MainActor to the background packetInputQueue.async.
    • Ensures UI state updates are correctly dispatched back to the @MainActor once background processing completes.

Impact

  • Eliminates UI scroll drops and freezes on the Home and Health views when triggering packet imports or recalculating scores.
  • Significantly reduces CPU cycles spent on JSON serialization/deserialization across the C-FFI bridge during background sync.

tigercraft4 referenced this pull request in tigercraft4/goose Jun 3, 2026
4 plans across 4 waves covering all 9 upstream PRs in risk-ascending
order (FORK-01 through FORK-10). PR #12 marked autonomous: false.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
tigercraft4 referenced this pull request in tigercraft4/goose Jun 3, 2026
tigercraft4 referenced this pull request in tigercraft4/goose Jun 3, 2026
…e in ROADMAP

All 9 upstream PRs integrated. PR #12 merged with no conflicts; cargo test passes.
Fork-specific infrastructure intact. Phase 5 complete.
tigercraft4 referenced this pull request in tigercraft4/goose Jun 5, 2026
4 plans across 4 waves covering all 9 upstream PRs in risk-ascending
order (FORK-01 through FORK-10). PR #12 marked autonomous: false.
tigercraft4 referenced this pull request in tigercraft4/goose Jun 5, 2026
tigercraft4 referenced this pull request in tigercraft4/goose Jun 5, 2026
…e in ROADMAP

All 9 upstream PRs integrated. PR #12 merged with no conflicts; cargo test passes.
Fork-specific infrastructure intact. Phase 5 complete.
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.

1 participant