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

High CPU usage if app doesn't have any windows #2719

Open
4 tasks done
Exidex opened this issue Jan 5, 2025 · 0 comments
Open
4 tasks done

High CPU usage if app doesn't have any windows #2719

Exidex opened this issue Jan 5, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@Exidex
Copy link
Contributor

Exidex commented Jan 5, 2025

Is your issue REALLY a bug?

  • My issue is indeed a bug!
  • I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • My hardware is compatible and my graphics drivers are up-to-date.

What happened?

Using following code, after closing window, CPU shoots up to 95%. Doesn't happen every time. Tested macOS and Linux

use iced::widget::text_input;
use iced::window;
use iced::{Element, Task};

fn main() -> iced::Result {
    iced::daemon("High CPU", Example::update, Example::view)
        .run_with(Example::new)
}

struct Example;

#[derive(Debug, Clone)]
enum Message {
    WindowOpened(window::Id),
}

impl Example {
    fn new() -> (Self, Task<Message>) {
        let (_id, open) = window::open(window::Settings::default());

        (
            Self,
            open.map(Message::WindowOpened),
        )
    }

    fn update(&mut self, message: Message) -> Task<Message> {
        match message {
            Message::WindowOpened(id) => {
                text_input::focus(format!("input-{id}"))
            }
        }
    }

    fn view(&self, window_id: window::Id) -> Element<Message> {
        text_input("Input", "Value")
            .id(format!("input-{window_id}"))
            .into()
    }
}

On macOS I tracked it down to os creating a lot of kCFRunLoopAfterWaiting events here and the app is getting a spammed with following events

NewEvents(ResumeTimeReached { start: Instant { tv_sec: 1936325, tv_nsec: 582125083 }, requested_resume: Instant { tv_sec: 1936321, tv_nsec: 90415500 } })
NewEvents(ResumeTimeReached { start: Instant { tv_sec: 1936325, tv_nsec: 582146958 }, requested_resume: Instant { tv_sec: 1936321, tv_nsec: 90415500 } })
NewEvents(ResumeTimeReached { start: Instant { tv_sec: 1936325, tv_nsec: 582169166 }, requested_resume: Instant { tv_sec: 1936321, tv_nsec: 90415500 } })
NewEvents(ResumeTimeReached { start: Instant { tv_sec: 1936325, tv_nsec: 582355291 }, requested_resume: Instant { tv_sec: 1936321, tv_nsec: 90415500 } })

It seems to be happening on both released 0.13 and master branch

What is the expected behavior?

CPU usage stays close to 0%

Version

master

Operating System

macOS and Linux

Do you have any log output?

No response

@Exidex Exidex added the bug Something isn't working label Jan 5, 2025
@Exidex Exidex changed the title High CPU usage on macOS if app doesn't have any windows High CPU usage if app doesn't have any windows Jan 5, 2025
Exidex added a commit to project-gauntlet/gauntlet that referenced this issue Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant