Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS. High CPU usage when application does nothing. #3816

Open
VladasZ opened this issue Jul 23, 2024 · 7 comments · May be fixed by #3906
Open

iOS. High CPU usage when application does nothing. #3816

VladasZ opened this issue Jul 23, 2024 · 7 comments · May be fixed by #3906
Assignees
Labels
B - bug Dang, that shouldn't have happened DS - ios

Comments

@VladasZ
Copy link

VladasZ commented Jul 23, 2024

Description

I noticed that my iPhone gets really hot when I run my projects. While trying to debug this issue I stripped all my code and only winit code remained but the phone was still hot.

I see that Xcode shows constant CPU load:
image

The same project has 0 CPU load on Android:
image
On Windows:
image
On Linux:
image
And on macOS:
image

What may cause the issue?

Minimal example to reproduce:

Rust code:

#[no_mangle]
pub extern "C" fn start_test_game() -> std::ffi::c_int {
    use winit::{
        application::ApplicationHandler,
        event::WindowEvent,
        event_loop::{ActiveEventLoop, ControlFlow, EventLoop},
        window::WindowId,
    };

    struct App;

    impl ApplicationHandler for App {
        fn resumed(&mut self, event_loop: &ActiveEventLoop) {}
        fn window_event(&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {}
    }

    let event_loop = EventLoop::new().unwrap();

    event_loop.set_control_flow(ControlFlow::Wait);

    event_loop.run_app(&mut App).unwrap();
    0
}

main.m in Xcode project:

int start_test_game(void);

int main(int argc, char * argv[]) {
    return start_test_game();
}

Device and iOS version

iPhone 13 Pro running iOS 17.5.1,
iPhone 5s running iOS 12.5.7,
iPhone 15 Simulator running iOS 17.4

Winit version

0.30.1

@VladasZ VladasZ added B - bug Dang, that shouldn't have happened DS - ios labels Jul 23, 2024
@lsy969999
Copy link

src/platform_impl/ios/app_state.rs -> new function in EventLoopWaker impl block

when i changed interval time param that repeated too often, cpu usage down to zero percent but i dont know the function and side effect

test code is same your
test device is my real iPhone 15 pro max iOS 17.6
test winit version is 0.30.0

스크린샷 2024-08-09 10 59 27
스크린샷 2024-08-09 11 01 17
스크린샷 2024-08-09 11 01 54

@PWhiddy
Copy link

PWhiddy commented Aug 13, 2024

@lsy969999
Sorry if this is a bit off topic, but is your application open source or do you know of a minimal iOS winit example? I've tried setting it up in the obvious way, and have no trouble getting it to work on desktop, but when my application starts up I'm not receiving any touch events.

@lsy969999
Copy link

@PWhiddy
bevy repo uses winit,
https://github.com/bevyengine/bevy/tree/main/examples
test ios example

@PWhiddy
Copy link

PWhiddy commented Aug 13, 2024

Thanks. I have built the bevy iOS example and it works fine for me, but the bevy codebase is complicated enough that it seemed like non-trivial work to extract that sample to a standalone minimal example. Are there any projects that use winit on iOS besides bevy?

@lsy969999
Copy link

Sorry, I learned about winit through Bevy, so I don't know about other examples using winit...
Maybe tauri, egui, etc. use winit?

@PWhiddy
Copy link

PWhiddy commented Aug 13, 2024

I have been using egui though I'm not sure if its meant to support iOS out of the box. Currently investigating this repo which uses a forked egui:
https://github.com/lucasmerlin/egui-apple-example

@madsmtm
Copy link
Member

madsmtm commented Sep 10, 2024

Indeed the problem here seems to be our CFRunLoopTimer, I think it gets triggered as-if you were using ControlFlow::Poll. Will assign myself and fix the issue before v0.31

@madsmtm madsmtm self-assigned this Sep 10, 2024
@madsmtm madsmtm added this to the Version 0.31.0 milestone Sep 10, 2024
@madsmtm madsmtm linked a pull request Sep 10, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened DS - ios
Development

Successfully merging a pull request may close this issue.

4 participants