Hey all,
I’m exploring the feasibility of building an robotics platform entirely in Swift 6 and higher.. My goal is to simplify the development and deployment of robotics platforms, including actuators that operate at frequencies exceeding 100 Hz. However, I’d like to understand potential performance pitfalls of using Swift in these scenarios compared to the industry-standard approach of C++.
Most robotics companies prototype in Python and transition to C++ for production. Even worse, is that most companies will even pick tons of different languages like JS, Java, Ruby, and Rust fragmenting any chance of community or interoperability of packages. I believe Swift offers a more modern, developer-friendly alternative while still allowing interop with C++ for performance-critical components. Swift also has an escape hatch for high performance code with Swift/C and Swift/C++ interop provides an escape hatch for developers who need extreme performance, making the case for Swift even stronger.
Key Questions and Concerns
- Bounds Checking and Heap Allocation: Swift arrays perform bounds checking and are heap-allocated, which can introduce latency. I came across the proposal for fixed-size arrays (or vector types) here. Could these types significantly improve performance, especially in real-time contexts?
- Automatic Reference Counting (ARC): Swift’s ARC adds overhead compared to manual memory management in C++. However, with borrow checking and the consume keyword introduced in Swift, can this overhead be mitigated effectively for robotics use cases?
- Deterministic Performance: Robotics systems often demand deterministic, low-latency performance. Does Swift currently offer sufficient control over memory and resource management to meet these demands, or are there scenarios where C++ will always have the upper hand?
- Concurrency: Swift’s structured concurrency model is compelling, but how does its real-time performance compare to C++-based approaches like std::thread or custom event loops?
Correct me if I'm wrong on any of my assumptions.
Looking for feedback and insights
- Any benchmarks or use cases where Swift has been evaluated for high-performance, real-time systems.
- Experience using Swift for applications requiring deterministic performance.
- Specific pitfalls or limitations when using Swift for performance-critical robotics or actuator systems.
- What are somethings I can do to overcome challenges of Swift 6.0.0 today for extreme performance scenarios?
I’m convinced that Swift has the potential to disrupt the current JavaScript/Java/Python/C++ pipeline in robotics by offering both developer productivity and performance. If we can leverage its features effectively while addressing performance bottlenecks, we could make robotics and IoT development significantly more accessible. What Apple has done with standardizing edge mobile development I think is an excellent analogue for what could be done in IoT, Robotics and Edge devices.
Correct me if I'm wrong anywhere on my assumptions. Absolutely tell me if Swift could never deliver in this area.