Works on iOS 17 and macOS 14. Just open ConcurrencyTest.xcodeproj
in App
folder with Xcode and run the app.
Simple test to check different concurrency strategies in Swift when an app have high CPU load. Examples are:
- Run on main thread
- Run on custom thread1
- Run using regular async/await
- Run using simple actor
- Run using an actor with worker pool pattern
- High cpu loader is an actor with custom executor2
- Run using an actor with worker pool pattern, where each worker is high cpu loader actor with custom executor2
Screenshots of the app and CPU usage:
![](https://private-user-images.githubusercontent.com/5507330/302032270-97a83521-cf52-474a-ae39-fd39d0c5ccaa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5NDE4NTMsIm5iZiI6MTcxOTk0MTU1MywicGF0aCI6Ii81NTA3MzMwLzMwMjAzMjI3MC05N2E4MzUyMS1jZjUyLTQ3NGEtYWUzOS1mZDM5ZDBjNWNjYWEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDJUMTczMjMzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjFhYzRhODRjNjY2M2QzZGVjM2M1MzJiOTkwNzVmN2MwMTA2ODViNzM2ODM3NmJlOTFhMjJkZTk0MmE5ZDM1NiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.AUr-tJxxkaMNcRsrQ0NT3qQYvRrUIPDlYo5Nx0teOvo)
![](https://private-user-images.githubusercontent.com/5507330/302032272-92a951db-56a1-4258-a89a-61256f36fef4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5NDE4NTMsIm5iZiI6MTcxOTk0MTU1MywicGF0aCI6Ii81NTA3MzMwLzMwMjAzMjI3Mi05MmE5NTFkYi01NmExLTQyNTgtYTg5YS02MTI1NmYzNmZlZjQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDJUMTczMjMzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OTU1M2MxMzQwOGMyM2Q4MjQ2MzU2NGNlOGQ0NzgwNjhkNzZhY2M1OWUwZjBiNjVjYmE2MWRkMjRjMmMzNzQ2OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.G3WqahXxpHEVTkBLL-J_NZ4JLzaEzm7eK1p7_qFoM0k)
On the left it's regular async/actor stuff. It's actually quite heavy and even makes M1 life a bit hard. You can notice it when running an app on macOS and sending app to background and back again. On the right it's 2 workers with custom threads, it takes longer to run execution, but everything is completely smooth.