Skip to content

Replace runtime discovery with static observation - #12

Merged
sonmbol merged 4 commits into
mainfrom
feature/generated-static-observation
Jul 27, 2026
Merged

Replace runtime discovery with static observation#12
sonmbol merged 4 commits into
mainfrom
feature/generated-static-observation

Conversation

@sonmbol

@sonmbol sonmbol commented Jul 26, 2026

Copy link
Copy Markdown
Owner

What changed

  • Replaced Objective-C/SKIE runtime state-flow discovery with compile-time-generated, statically typed observation plans.
  • Added dedicated core, SKIE, NativeCoroutines, and macro targets with single-responsibility source files.
  • Added shared per-model observation hubs so multiple SwiftUI consumers reuse one collection and duplicate values are suppressed before invalidation.
  • Preserved StateObject factory laziness so repeated SwiftUI view-value construction does not allocate throwaway Kotlin ViewModels.
  • Hardened ownership, rebinding, reentrant cancellation, failure routing, optional-child observation, and writable projected bindings.
  • Reorganized the DailyPulse examples and updated package documentation, DocC, API checks, CI configuration, and changelog.
  • Added macro, lifecycle, cancellation, concurrency, deduplication, rebinding, laziness, and performance coverage.

Why

Runtime selector discovery was expensive, fragile across generated ABI changes, and unable to provide compile-time guarantees. Eager factory evaluation also violated StateObject lifetime semantics by constructing a new Kotlin model whenever a parent recreated the SwiftUI view value.

The new architecture makes observation routes explicit and type-checked while preserving SwiftUI identity through stable, lazily realized StateObject storage. Shared hubs use allocation-light integer listener IDs, support reentrant teardown, and deregister from the weak registry in constant time.

Impact

Applications declare observable KMP ViewModels once with @KMPObservable. SwiftUI owners and observers retain native APIs while gaining deterministic teardown, shared collection, fewer redundant invalidations, and exporter-specific integration modules.

This intentionally changes the automatic-observation integration surface for the next major version; explicit adapters remain available as an exporter-neutral fallback.

Validation

  • swift test -Xswiftc -strict-concurrency=complete -Xswiftc -warnings-as-errors — 36 tests passed
  • xcodebuild docbuild -scheme KMPObservableBridge -destination 'generic/platform=iOS Simulator' CODE_SIGNING_ALLOWED=NO — passed
  • swift package dump-package — passed
  • ./Scripts/check-api.sh — passed (API baseline is not configured)
  • Runtime-interception source audit — passed
  • git diff --check — passed
  • Release performance guardrails remain in the prior steady-state range after warm-up

@sonmbol
sonmbol merged commit a4d6252 into main Jul 27, 2026
1 check passed
@sonmbol
sonmbol deleted the feature/generated-static-observation branch July 27, 2026 07: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.

1 participant