performancegouser-interfacefyne

Im having trouble with Fyne in GoLang


Im writting a project and i need to show some images in layout for example 12 images in a 3x4, i had never used any UI framework in go and decided to go with fyne becouse it seemed easy. My problem is when i update the images it takes like 3 seconds to update only 12 images, and i need it to be faster, im not saying instant but like 1,5 seconds could be fine. I only get that performance with less images

I am using imageGallery = container.NewAdaptiveGrid(3)

And adding images with

imagesToAdd := make([]fyne.CanvasObject, 0, batch)
for i := imgOffset; i < imgOffset+batch; i++ {
    imagesToAdd = append(imagesToAdd, cacheImages[i])
}
imageGallery.Objects = append(imageGallery.Objects, imagesToAdd...)
...
imageGallery.Refresh()

I have tested the function a lot, it is INSTANT but fyne takes a lot of time, i have tried other types of containers, I assume fyne takes to long to calculete where each image should get placed as only 1 or 2 images is instant.

Really need help and if there is a need of more code just comment thanks.

func showNewImagesArray() {
    imageGallery.RemoveAll()

    batch := 12 // numbers of images to add
    
    if imgOffset+batch > len(cacheImages) {
        batch = len(cacheImages) - imgOffset
    }

    imagesToAdd := make([]fyne.CanvasObject, 0, batch)
    for i := imgOffset; i < imgOffset+batch; i++ {
        imagesToAdd = append(imagesToAdd, cacheImages[i])
    }
    imageGallery.Objects = append(imageGallery.Objects, imagesToAdd...)

    imgOffset += batch
    imageGallery.Refresh()
    log.Println("showNewImagesArray completed")
}


func createUI() {
    imgOffset = 0
    
    mainApp = app.New()
    mainWindow = mainApp.NewWindow("Fyne App with Systray")
    imageGallery = container.NewAdaptiveGrid(3)

    content := container.NewVBox(
        imageGallery,
    )

    mainWindow.SetContent(content)
    mainWindow.SetCloseIntercept(func() {
        mainWindow.Hide()
    })

    mainWindow.ShowAndRun()
}

cacheimages is part of other side of the program


Solution

  • The most likely issue is that your images are large. If you put 4k images into a grid then every time it refreshes the toolkit will have to transfer all that data to the GPU which is very wasteful.

    The layout algorithms are certainly not slow, try adding thumbnailing in your code - or testing it with smaller images to be sure :).

    Images are surprisingly complex to do with good performance but there are many libraries out there that can scale images efficiently so you are only rendering the required number of pixels.