wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.28k stars 1.22k forks source link

Way to partition CPU between backend and UI #690

Closed rh12503 closed 3 years ago

rh12503 commented 3 years ago

Right now on Windows, if the backend uses 100% of all CPU cores (eg. multiple Goroutines to calculate something), the UI freezes. This has been an issue for my app https://github.com/RH12503/triangula/issues/5, which uses all CPU cores available when running.

Is there any way to allocate a portion of the CPU to the front end to avoid UI freezes?

leaanthony commented 3 years ago

Interesting... looking into this, many people believe this is best solved by the OS. Have you tried setting GOMAXPROCS?

rh12503 commented 3 years ago

Yes, but it doesn't seem to have any effect so I'm guessing GOMAXPROCS restricts the entire application?

leaanthony commented 3 years ago

Ah, I see what you're saying, regardless of how many are allocated, the fight is between frontend and backend. Normally, the GUI is running on the main thread so maybe there's a way to prioritise or pin it. Also, just for I.rarest, have you tried adding some sleep() in the Go code?

rh12503 commented 3 years ago

I haven't been able to get my Windows machine working recently, but I think that sleep() would just slow down the entire app. My app only uses 100% of the cores around 70% of the time so it shouldn't be completely frozen.

Do you think using SetThreadPriority() on the UI thread would work?

forgotPassword commented 3 years ago

2 cents: for me the app ui froze even with just 1 (heavy) thread out of 8. Overall system cpu was 30% and not 100%. It seems the ui and work thread are shared.

leaanthony commented 3 years ago

Yeah right. I wonder if this is a new thing and there's been a change to the Go scheduler. All your bound methods run in Go routines so it's weird you should see this. Do you have an example that reproduces the issue?

rh12503 commented 3 years ago

I managed to test it out on a Windows VM, and I've realized the issue is that ie11's SVG renderer is very slow. Sorry for bothering you about this!

rh12503 commented 3 years ago

The issue is very specific to my app, as I need to render thousands of triangles multiple times per second, but I suppose a sentence could be: "MSHTML's SVG renderer's performance is slower than other browsers, consider using an HTML <canvas> element instead."

Hopefully v2 will change this!