Skip to content
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 usage when drawing a table with 288 items #4156

Open
2 tasks done
roffe opened this issue Aug 14, 2023 · 7 comments
Open
2 tasks done

High cpu usage when drawing a table with 288 items #4156

roffe opened this issue Aug 14, 2023 · 7 comments
Labels
unverified A bug that has been reported but not verified

Comments

@roffe
Copy link
Contributor

roffe commented Aug 14, 2023

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

Displaying a simple table uses 6-14% CPU on a Intel i9-9900k.

Moving the mouse pointer around in the window spikes 1 core to almost 100% CPU

clicking and marking a cell is noticeably laggy and takes upwards half a second for the blue border to move

I can see the update function is constantly being called just by moving the mouse pointer in the window which might be the culprit causing it to call SetText on all 288 entries even though nothing changed

How to reproduce

Run example program which has 288 data points that needs to be displayed in the table

Screenshots

No response

Example code

package main

import (
	"strconv"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

var yValues = []int{6200, 5820, 5440, 5060, 4680, 4300, 3920, 3540, 3160, 2780, 2400, 2020, 1640, 1260, 880, 700}
var xValues = []int{25, 75, 125, 180, 240, 300, 360, 420, 480, 540, 600, 660, 720, 780, 840, 900, 1050, 1300}

var valueMap = [][]float64{
	{0.86, 0.90, 0.92, 0.94, 0.97, 1.00, 1.11, 1.13, 1.15, 1.16, 1.17, 1.19, 1.21, 1.24, 1.32, 1.32, 1.40, 1.45},
	{0.86, 0.90, 0.92, 0.94, 0.97, 1.00, 1.02, 1.11, 1.13, 1.13, 1.14, 1.15, 1.17, 1.18, 1.27, 1.30, 1.37, 1.42},
	{0.85, 0.89, 0.92, 0.95, 0.97, 1.01, 1.01, 1.01, 1.09, 1.10, 1.11, 1.11, 1.13, 1.14, 1.21, 1.25, 1.35, 1.40},
	{0.86, 0.90, 0.93, 0.95, 0.97, 0.99, 1.00, 1.01, 1.02, 1.07, 1.09, 1.10, 1.12, 1.13, 1.15, 1.22, 1.29, 1.34},
	{0.86, 0.93, 0.93, 0.94, 0.96, 0.97, 1.02, 1.01, 1.02, 1.02, 1.08, 1.09, 1.11, 1.12, 1.14, 1.15, 1.27, 1.31},
	{0.85, 0.91, 0.91, 0.92, 0.96, 0.97, 1.00, 1.02, 1.02, 1.02, 1.02, 1.07, 1.10, 1.11, 1.13, 1.14, 1.24, 1.27},
	{0.84, 0.92, 0.92, 0.92, 0.96, 0.99, 0.98, 1.02, 1.01, 1.02, 1.01, 1.01, 1.07, 1.09, 1.12, 1.13, 1.20, 1.25},
	{0.84, 0.90, 0.91, 0.92, 0.95, 0.97, 0.99, 1.00, 1.01, 1.01, 1.01, 1.01, 1.05, 1.07, 1.10, 1.12, 1.18, 1.22},
	{0.84, 0.91, 0.91, 0.92, 0.94, 0.98, 1.00, 1.01, 1.01, 1.01, 1.01, 1.01, 1.01, 1.06, 1.09, 1.10, 1.16, 1.18},
	{0.91, 0.93, 0.92, 0.93, 0.95, 0.97, 1.00, 1.01, 1.01, 1.01, 1.01, 1.01, 1.00, 1.06, 1.08, 1.09, 1.11, 1.12},
	{0.94, 0.92, 0.91, 0.94, 0.95, 0.95, 0.98, 1.00, 1.01, 1.01, 1.01, 1.01, 1.00, 1.06, 1.06, 1.08, 1.10, 1.11},
	{0.95, 0.90, 0.89, 0.92, 0.94, 0.97, 0.97, 0.99, 1.01, 1.01, 1.01, 1.01, 1.06, 1.07, 1.07, 1.08, 1.10, 1.10},
	{0.93, 0.88, 0.89, 0.91, 0.95, 0.97, 0.98, 0.98, 0.99, 1.02, 1.01, 1.01, 1.06, 1.08, 1.09, 1.09, 1.09, 1.09},
	{0.91, 0.87, 0.87, 0.89, 0.95, 0.98, 0.99, 1.00, 1.01, 0.99, 0.99, 1.06, 1.06, 1.08, 1.08, 1.08, 1.08, 1.08},
	{0.87, 0.83, 0.88, 0.88, 0.94, 0.98, 1.00, 1.02, 1.02, 1.03, 1.03, 1.06, 1.07, 1.08, 1.08, 1.08, 1.08, 1.08},
	{0.87, 0.83, 0.89, 0.89, 0.90, 0.97, 1.00, 1.00, 0.99, 1.00, 1.00, 1.06, 1.07, 1.08, 1.08, 1.08, 1.08, 1.08},
}

func main() {
	numRows := len(yValues)
	numColumns := len(xValues)

	a := app.New()
	w := a.NewWindow("Table Test")
	w.Resize(fyne.NewSize(1100, 800))

	t := widget.NewTable(func() (int, int) {
		return numRows + 1, numColumns + 1
	}, func() fyne.CanvasObject {
		return widget.NewEntry()
	}, func(i widget.TableCellID, o fyne.CanvasObject) {
		oo := o.(*widget.Entry)
		if i.Row == 0 && i.Col == 0 {
			oo.Hide()
			return
		}
		if i.Col == 0 {
			strconv.Itoa(yValues[i.Row-1])
			oo.Disable()
		} else if i.Col > 0 && i.Row == 0 {
			oo.SetText(strconv.Itoa(xValues[i.Col-1]))
			oo.Disable()
		} else {
			oo.SetText(strconv.FormatFloat(valueMap[i.Row-1][i.Col-1], 'f', 2, 64))
		}
	})

	for i := 0; i <= numColumns; i++ {
		t.SetColumnWidth(i, 50)
	}

	w.SetContent(container.NewMax(t))

	w.ShowAndRun()
}

Fyne version

2.3.5

Go compiler version

1.21

Operating system and version

Windows 11

Additional Information

No response

@roffe roffe added the unverified A bug that has been reported but not verified label Aug 14, 2023
@Jacalz
Copy link
Member

Jacalz commented Aug 14, 2023

Thanks for the report. There have been quite a lot of changes to the Table widget for the upcoming release. Would you mind trying out the develop branch to see if the issue still exists?

@roffe
Copy link
Contributor Author

roffe commented Aug 14, 2023

A little better cpu usage. muchr snappier. also it does not extensively call the update function 👍🏻

Resizing the window so it's smaller than the table and then dragging it out bigger again crashes the test code tougt :/

@andydotxyz
Copy link
Member

Can you provide the crash log so we can test against it please? Sounds like something that needs fixed for release.

@roffe
Copy link
Contributor Author

roffe commented Aug 15, 2023

This is how it should look
image

After resizing the window and dragging it to be bigger again
image
image

@roffe
Copy link
Contributor Author

roffe commented Aug 15, 2023

it doesn't crash today when i try it so wondering if it is some racecondition that made the window lock up yesterday

@andydotxyz
Copy link
Member

Did it crash or hang before?

P.s. I think you're missing calls to Show() and Enable() in your test code

@andydotxyz
Copy link
Member

I cannot see any CPU usage when the table is displayed. Perhaps this is a duplicate of #1946?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unverified A bug that has been reported but not verified
Projects
None yet
Development

No branches or pull requests

3 participants