3 ms·
There are many memory safe languages, but not many of those are compiled and able to offer performance that is in the same ballpark as C. Rust and Swift are th
by GeekyBear 2y ago
There are many memory safe languages, but not many of those are compiled and able to offer performance that is in the same ballpark as C.
Rust and Swift are the two most widely used.
Interestingly, Swift had interoperating with C as an explicit design goal, while Rust had data race safety as a design goal.
Now we have data race safety added in the latest version of Swift, and Rust looking to improve interoperability with C.
- Narishma 2y agoI was under the impression that Swift was more in the Go/C# bucket rather than Rust/C++ in terms of performance.
- pjmlp 2y agoSwift's long term roadmap is to be usable in all scenarios Apple currently uses C, Objective-C and C++ for, it is even on its official documentation and product description site. How much it gets there, depends on squizzing juice out of LLVM backend for Swift code.
- GeekyBear 2y agoGiven that the person who created LLVM also created Swift, the ability to be used as a systems programming language was always there. Chris Lattner, the creator of both LLVM and Swift, has referred to Swift as “syntactic sugar for LLVM.” They are deeply tied together. The amount of Swift code in Apple's operating systems has increased every year. https://blog.timac.org/2023/1019-state-of-swift-and-swiftui-ios17/ https://blog.timac.org/2023/1019-state-of-swift-and-swiftui-... Lattner gave an interview looking at the advantages of reference counting over the sort of garbage collection used in languages like Java, C#, and Go while still avoiding error-prone manual memory management. > ARC has clear advantages in terms of allowing Swift to scale down to systems that can’t tolerate having a garbage collector, for example, if you want to write firmware in Swift. I think that it does provide a better programming model where programmers think just a little bit about memory. https://atp.fm/205-chris-lattner-interview-transcript#gc https://atp.fm/205-chris-lattner-interview-transcript#gc
- GeekyBear 2y agoReference counting doesn't have the same cost as a sweeping garbage collector. Apple has also optimized their custom ARM core to further reduce the cost. > retaining and releasing an NSObject takes ~30 nanoseconds on current gen Intel, and ~6.5 nanoseconds on an M1 https://blog.metaobject.com/2020/11/m1-memory-and-performance.html?m=1 https://blog.metaobject.com/2020/11/m1-memory-and-performanc... That said, Swift is working toward adding a future opt-in Rust inspired approache to memory management for those who need it. https://forums.swift.org/t/manifesto-ownership/5212 https://forums.swift.org/t/manifesto-ownership/5212 https://forums.swift.org/t/a-roadmap-for-improving-swift-performance-predictability-arc-improvements-and-ownership-control/54206 https://forums.swift.org/t/a-roadmap-for-improving-swift-per...