-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 and sluggishness running a simple wasm app #5073
Comments
I'm aware of #4641 as well, but as I said already, this issue is with an idling app. |
This uses very little CPU, when run as a wasm app, but it has no text input: package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
type customLayout struct {
split *container.Split
}
func (c *customLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
c.split.Resize(size)
}
func (c *customLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
return c.split.MinSize()
}
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("Four Regions App")
// Top region
topRegion := widget.NewLabel("Top Region")
topRegion.Alignment = fyne.TextAlignCenter
// Middle resizable regions
middleRegion1 := widget.NewLabel("Middle Region 1 (Resizable)")
middleRegion1.Alignment = fyne.TextAlignCenter
middleRegion2 := widget.NewLabel("Middle Region 2 (Resizable)")
middleRegion2.Alignment = fyne.TextAlignCenter
// Bottom region
bottomRegion := widget.NewLabel("Bottom Region")
bottomRegion.Alignment = fyne.TextAlignCenter
// Create a split container for the middle resizable regions
split := container.NewVSplit(
container.NewVBox(middleRegion1),
container.NewVBox(middleRegion2),
)
// Create a custom layout to wrap the split container
customSplit := container.New(&customLayout{split: split}, split)
// Set up the main container with all regions
content := container.NewBorder(
container.NewVBox(topRegion),
container.NewVBox(bottomRegion),
nil,
nil,
customSplit,
)
// Set minimum window size
myWindow.Resize(fyne.NewSize(400, 300))
myWindow.SetContent(content)
// Common callback function to print dimensions
printDimensions := func() {
fmt.Printf("Window size: %v\n", myWindow.Canvas().Size())
fmt.Printf("Top region size: %v\n", topRegion.Size())
fmt.Printf("Middle region 1 size: %v\n", middleRegion1.Size())
fmt.Printf("Middle region 2 size: %v\n", middleRegion2.Size())
fmt.Printf("Bottom region size: %v\n", bottomRegion.Size())
fmt.Println("------------------------")
}
// Callback for window resize
myWindow.Canvas().SetOnTypedKey(func(ke *fyne.KeyEvent) {
if ke.Name == fyne.KeyF11 {
fmt.Println("Window resized")
printDimensions()
}
})
myWindow.ShowAndRun()
} |
Alright, this might be related to #4641 and therefore possibly a duplicate. |
I'm guessing this is with the entry focused? There is a cursor animation that you could turn off to see if it's related (by disabling animations in the build). |
Yeah, that makes sense. Yes, that is with the entry focused. That explains why the app with no blinking cursor does not have the CPU usage at idle. I'll try disabling the cursor animation. |
Disabling the animations also made the cursor invisible for me (local x11, not in the browser). Offhand I don't see a way in Removed the wasm directory, rebuilt it with Served it with package main
import (
"fmt"
"net/http"
)
func main() {
fs := http.FileServer(http.Dir("./wasm")) // Serve from the 'web' directory
http.Handle("/", fs)
fmt.Println("Server started at http://localhost:8080")
http.ListenAndServe(":8080", nil)
} The cursor in the web page is now no longer animated, but it is now not visible as well. Also, the cpu usage is very low, so it is the blinking cursor that was consuming the CPU. |
There is a PR open to fix this already :).
That is fixed on the release branch in preparation for v2.5.1 coming soon. |
Alight, since I know what is going on, I'll close this. Especially with the mitigations you mentioned. |
Checklist
Describe the bug
Example app when idling uses a lot of CPU.
When entering in text it feels sluggish.
With chromium running nothing, it is at very low CPU usage. See screenshots.
Just running https://get.webgl.org/?ref=colonist-blog around 14% and 8% (2 cores)
Just running the provided example code
fyne serve --sourceDir client
around 16 and 18% (2 cores)Firefox shows similar results.
GPU acceleration is being used. See screenshots.
How to reproduce
fyne serve --sourceDir client
with the provided example code in the directoryclient
Wait for app to load then look at CPU usage.
Type in text into the entry box and press enter (or press the button).
Screenshots
chromium idle
chromium just running https://get.webgl.org/?ref=colonist-blog
chromium just running the provided example fyne wasm app
GPU is being used
Chromium version 127
Example code
Fyne version
fyne version v2.5.0
Go compiler version
go version go1.23.0 linux/amd64
Operating system and version
AlmaLinux 9.4 x86_64
Additional Information
This might be related to #2803 but this is with an idling app.
chrome:://gpu
shows:The text was updated successfully, but these errors were encountered: