3 ms·
Since a lot of people are discussing Apple’s plans to replace C/C++ in performance critical areas, I’m curious to discuss it. How do they plan to make Swift act
by meisel 3y ago
Since a lot of people are discussing Apple’s plans to replace C/C++ in performance critical areas, I’m curious to discuss it. How do they plan to make Swift actually match those languages in speed? Last I checked, classes, along with fundamental struct types like Array and String, use atomic reference counting. Do they plan to ban all those types in these systems? Are there any highly performance sensitive and C/C++ Apple systems (not just libraries) that have been rewritten in Swift without a drop in speed? The rewrite of the Swift compiler from C++ to Swift is an example of where rewriting is occurring but where there’s a non trivial performance loss as a result.
- adamwk 3y agoA lot of work is going into move only types for swift to avoid the need of ARC in fundamental types like you mentioned. Classes aren’t going away but Apple is trying to evolve the language to cater to various performance needs. https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md https://github.com/apple/swift-evolution/blob/main/proposals...
- nivenhuh 3y agoI think you mean automatic reference counting (ARC) — and ARC happens at compile time as part of a static analysis pass. (The compiler is basically adding retain/release code for you.) At runtime, it’s functionally close(ish) to malloc/free and doesn’t carry much overhead.
- steveklabnik 3y agoIn my understanding, it’s both: you’re right about Automatic Reference Counting (ARC) being a compile time pass. But the reference counts that they use for said retain/release are atomic reference counted (ARC). ARC certainly helps ARC be more performant than ARC without ARC due to the elided traffic on the count. (lol)
- zer0zzz 3y agoSo, the buildin stdlib types afaict use arc only to figure out if the instance has a single unique reference. Internally it is a value type. If a variable on one of these types is modified then the existence of more than one reference is used to do a deep copy of the internal value type. Also, internally the stdlib uses objc arc types nsarray nsstring etc only on Darwin platforms for zero overhead objc interop. This isn't the case on Linux and windows. For some embedded or Micro-swift variant for low level os work there could be a similar stdlib toggle for Darwin I think.
- slavapestov 3y ago> The rewrite of the Swift compiler from C++ to Swift is an example of where rewriting is occurring but where there’s a non trivial performance loss as a result. Citation needed on the performance loss. So far only a handful of SIL optimizer passes have been rewritten in Swift.