Skip to content

Bevy on iOS is running into thread priority inversion issue #16762

Open
@wentao

Description

@wentao

Bevy version

0.14.2

[Optional] Relevant system information

cargo 1.82.0 (8f40fc59f 2024-08-21)

OS: iPhone 13

Adapter Metal AdapterInfo { name: "Apple A15 GPU", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }  

What you did

I've setup a simple iOS game using bevy https://github.com/80gen/bevy_ios_bug. The logic is quite simple as written in this file https://github.com/80gen/bevy_ios_bug/blob/main/crates/game/src/lib.rs

What went wrong

After the game starts, an error is shown in the console log

Thread Performance Checker: Thread running at User-interactive quality-of-service class waiting on a lower QoS thread running at Default quality-of-service class. Investigate ways to avoid priority inversions
PID: 11788, TID: 3420791
Backtrace
=================================================================
0   mini.debug.dylib                    0x000000010c3a819c _ZN3std3sys4sync6rwlock5queue6RwLock14lock_contended17hdcee594336442c59E + 432
1   mini.debug.dylib                    0x000000010b24847c _ZN76_$LT$async_broadcast..Receiver$LT$T$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17hdce52b5654520aceE + 344
2   mini.debug.dylib                    0x000000010b2fdd3c _ZN4core3ptr123drop_in_place$LT$async_broadcast..Receiver$LT$alloc..sync..Arc$LT$dyn$u20$bevy_asset..loader..ErasedAssetLoader$GT$$GT$$GT$17he332cb7023ddcab0E + 20
3   mini.debug.dylib                    0x000000010b2eccb0 _ZN10bevy_asset6server7loaders12AssetLoaders4push17h698c20b5669e22c1E + 328
4   mini.debug.dylib                    0x000000010b4bb174 _ZN10bevy_asset6server11AssetServer15register_loader17h4bb882b0882f5494E + 56
5   mini.debug.dylib                    0x000000010b3953e4 _ZN59_$LT$bevy_app..app..App$u20$as$u20$bevy_asset..AssetApp$GT$21register_asset_loader17hdfc89733d5b171d1E + 212
6   mini.debug.dylib                    0x000000010b2e23a8 _ZN78_$LT$bevy_render..texture..ImagePlugin$u20$as$u20$bevy_app..plugin..Plugin$GT$6finish17h671232cc9da778c3E + 60
7   mini.debug.dylib                    0x000000010bfc3958 _ZN8bevy_app3app3App6finish17h98b0b92f443de6d4E + 116
8   mini.debug.dylib                    0x0000000109ddc54c _ZN10bevy_winit5state12winit_runner17h25fe230de8dcaa8cE + 60
9   mini.debug.dylib                    0x0000000109e0f51c _ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h3efd20b3b43e33d6E + 40
10  mini.debug.dylib                    0x000000010bfc352c _ZN8bevy_app3app3App3run17h261f33f429ad232aE + 396
11  mini.debug.dylib                    0x0000000109dc6ca8 _ZN4game3run17h5289c38ebc2b783bE + 744
12  mini.debug.dylib                    0x0000000109da4038 main_rs + 12
13  mini.debug.dylib                    0x0000000109da401c __debug_main_executable_dylib_entry_point + 28
14  dyld                                0x00000001ba6eeec8 3060D36A-16CE-3C3A-9258-3881459F5714 + 212680

ChatGPT was giving me some hint like (not sure if it's useful)

In the context of Bevy and iOS, the issue could arise from Bevy’s multithreading design conflicting with iOS QoS priorities.

Bevy relies on parallel systems and tasks for performance, using rayon under the hood. The thread pool used by rayon may not align well with iOS QoS expectations, especially when running tasks with different priorities.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-TasksTools for parallel and async workC-BugAn unexpected or incorrect behaviorO-iOSSpecific to the iOS mobile operating systemS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions