nwg-piotr / nwg-drawer

Application drawer for wlroots-based Wayland compositors
MIT License
250 stars 27 forks source link

High CPU utilization #50

Closed Raffy23 closed 2 years ago

Raffy23 commented 2 years ago

Currently nwg-drawer uses a lot of cpu cycles for polling the USR1 signal and file change trigger variables at a high interval: https://github.com/nwg-piotr/nwg-drawer/blob/main/main.go#L494-L529. This can be avoided by using channels and a goroutine to only execute tasks in the event loop if necessary. For example, by changing showWindowTrigger into a channel and replacing the linked function with the following goroutine, the cpu utilization drops to 0 while not affecting the responsiveness.

go func() {
    for { 
        < -showWindowChannel;
        glib.TimeoutAdd(uint(0), func() bool {
            // Insert code to show window
            return false;
        });
    }
}()
nwg-piotr commented 2 years ago

Thanks for pointing this out. I'm currently fixing some issues in a related project, which may take some time. Would you like to contribute, and submit a PR? Same about the second issue.

Raffy23 commented 2 years ago

Sure, I can prepare PRs for these two issues.

nwg-piotr commented 2 years ago

Thanks in advance. I do need more contributions to all the nwg-shell project.