A SwiftUI Runtime in C++
a year ago
- #Performance Optimization
- #SwiftUI
- #C++
- Kulve's SwiftUI runtime is a cross-platform, multithreaded, fully async runtime written in C++ with minor Objective-C scaffolding.
- The runtime was developed to optimize performance for Kulve, aiming for a lightweight, fast, and efficient Twitch experience with extended battery life on Apple silicon.
- Performance optimization involved three key steps: eliminating data copies, managing a single instance of all data to avoid ownership issues, and connecting the runtime to SwiftUI using NotificationCenter.
- The runtime uses void* pointers for type erasure and efficient memory management, avoiding the overhead of std::any or std::variant.
- NotificationCenter is utilized to connect the runtime with SwiftUI, enabling direct communication without data copies and providing control over data lifetimes.
- The runtime includes mechanisms to handle thread management, data population, and message sending, with a focus on avoiding race conditions and nullptr dereferences.
- A deferred deallocation strategy is employed to ensure SwiftUI views complete their operations before data sources are deallocated.
- The runtime is part of a recent AppStore submission, with the developer open to discussions about its implementation details.