webui-dev / webui

Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library.
https://webui.me
MIT License
3.08k stars 187 forks source link

Linux WebView high CPU usage #511

Open Hejsil opened 3 weeks ago

Hejsil commented 3 weeks ago

When running webui with WebView as the browser the program ends in the following busy loop:

https://github.com/webui-dev/webui/blob/d5b25ca1a827d3ec07be9607232edb0c27172918/src/webui.c#L3099-L3101

This causes high CPU usage. Is there a reason why blocking = false is passed to gtk_main_iteration_do?

AlbertShown commented 3 weeks ago

the program ends

You mean unwanted exit, like a crash? Or a normal exit?

Is there a reason why blocking = false is passed to gtk_main_iteration_do?

I guess if blocking = true the websocket server will be blocked or something... you can easily test it to be sure. just change the line, and run make.

Hejsil commented 3 weeks ago

the program ends

You mean unwanted exit, like a crash? Or a normal exit?

Aaah no. I guess that is bad phrasing. The program will spin on this loop (100% CPU usage) after opening a window. So the program "ends up" here once the window has been opened.

Hejsil commented 3 weeks ago

I guess if blocking = true the websocket server will be blocked or something... you can easily test it to be sure. just change the line, and run make.

Aah ok. Just tested a little further. It does not seem this is the loop that causes 100% CPU usage. I just assumed (my bad)

Hejsil commented 2 days ago

Just pulled latest main branch and built examples/C/minimal and I still see this issue

image

Looking at usage, it seems that two cores are constantly at 100%. System info:

uname: Linux 6.8.0-49-generic #49-Ubuntu SMP PREEMPT_DYNAMIC Mon Nov  4 02:06:24 UTC 2024 x86_64
compiler info: gnuc: 13.2
libc info: glibc: 2.39
AlbertShown commented 2 days ago

I guess you are using a webview. Can you please change show() to use a web browser?

webui_show_browser(win, "<html><head><script src=\"webui.js\"></script></head> Hello World ! </html>", Chrome); // Or Firefox, whatever you have
Hejsil commented 2 days ago

I guess you are using a webview. Can you please change show() to use a web browser?

webui_show_browser(win, "<html><head><script src=\"webui.js\"></script></head> Hello World ! </html>", Chrome); // Or Firefox, whatever you have

No issues using Firefox as the browser

AlbertShown commented 2 days ago

Just to confirm, the screenshot you included it's a webview, right?

Hejsil commented 2 days ago

Just to confirm, the screenshot you included it's a webview, right?

Yes it is

AlbertShown commented 29 minutes ago

Fixed (https://github.com/webui-dev/webui/commit/984de15efaab4f0184f708b1ec4111f68628607b). Thank you @Hejsil for reporting this.

Can you please re-test and confirm?