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

Improve performance of content size calculation in List #4835

Merged
merged 2 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions widget/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,15 @@ func (l *List) contentMinSize() fyne.Size {
}

height := float32(0)
totalCustom := 0
templateHeight := l.itemMin.Height
for item := 0; item < items; item++ {
itemHeight, ok := l.itemHeights[item]
if ok {
for id, itemHeight := range l.itemHeights {
if id < items {
totalCustom++
height += itemHeight
} else {
height += templateHeight
}
}
height += float32(items-totalCustom) * templateHeight

return fyne.NewSize(l.itemMin.Width, height+separatorThickness*float32(items-1))
}
Expand Down
26 changes: 26 additions & 0 deletions widget/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,29 @@ func TestList_RefreshUpdatesAllItems(t *testing.T) {
list.Refresh()
assert.Equal(t, "0.0.", printOut)
}

var minSize fyne.Size

func BenchmarkContentMinSize(b *testing.B) {
b.StopTimer()

l := NewList(
func() int { return 1000000 },
func() fyne.CanvasObject {
return NewLabel("Test")
},
func(id ListItemID, item fyne.CanvasObject) {
item.(*Label).SetText(fmt.Sprintf("%d", id))
},
)
l.SetItemHeight(10, 55)
l.SetItemHeight(12345, 2)

min := fyne.Size{}
b.StartTimer()
for i := 0; i < b.N; i++ {
min = l.contentMinSize()
}

minSize = min
}