Swift’s native Clocks are inefficient

Swift’s Clock protocol, including ContinuousClock and SuspendingClock, has significant overhead which can become a bottleneck when dealing with frequent time and timing needs. Throttling UI updates based on I/O operation progress led to creating a custom throttling system due to poor performance of swift-async-algorithms. Benchmarking alternative time-tracking methods showed that Swift clocks are over an order of magnitude slower than traditional APIs. Notably, mach_absolute_time is the fastest but has limitations due to Apple’s restrictions. Surprisingly, Date’s performance is competitive with C-level APIs. Recent changes in Swift’s standard library aim to reduce overhead in clock implementations, potentially closing the performance gap.

https://wadetregaskis.com/swifts-native-clocks-are-very-inefficient/

To top