~eliasnaur/gio

1

repro to slower label.Layout() (was: commit 43c47f08835cbc3db slower by ~25%)

Details
Message ID
<CA+ctqroneS2MMm8BJ0LVPDC20JVVrwAKXEDBdydExDE=i5du6Q@mail.gmail.com>
DKIM signature
missing
Download raw message
I got distracted.
On my oldandsilent X on linux the following repro with commit babe7a2
is slower by 30% (or 50%, depending how you're looking at it) compared
to with commit 43c47f0 .

cheers,
Gergo

$ cat changeToCommit.sh
#!/bin/sh
# 43c47f0 slow commit -- material.NewTheme(gofont.Collection())
# babe7a2 latest fast commit -- material.NewTheme(gofont.Collection())

if [ $# -ne 1 ]; then
        echo "usage: $0 commithash"
        echo changing to 43c47f0
        ./$0 43c47f0
        exit 0
fi

rm -f go.mod go.sum
go mod init benchGiochange
go get gioui.org@$1
go mod tidy

$ cat cmd_test.go
package benchGiochange

import (
        "sync"
        "testing"

        "gioui.org/io/system"
        "gioui.org/layout"
        "gioui.org/op"
        "gioui.org/widget/material"
)

var once sync.Once

var t *material.Theme
var l material.LabelStyle
var gtx layout.Context

func setup() {
        t = material.NewTheme() // uncomment to use with commit 43c47f0
        //      t = material.NewTheme(gofont.Collection()) //
uncomment to use with commit babe7a2

        l = material.Label(t, 10, "abcdefghijklmnopqrstuvwxyz")
        gtx = layout.NewContext(&op.Ops{}, system.FrameEvent{})
}

func BenchmarkLayout(b *testing.B) {
        once.Do(setup)

        for n := 0; n < b.N; n++ {
                l.Layout(gtx)
        }
}

$ go test -bench=.
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
BenchmarkLayout-2         131176             15269 ns/op
PASS
ok      benchGiochange  2.123s
$ go test -bench=.
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
BenchmarkLayout-2         102066             16035 ns/op
PASS
ok      benchGiochange  1.758s
$ ./changeToCommit.sh babe7a2
go: creating new go.mod: module benchGiochange
go: to add module requirements and sums:
        go mod tidy
go: added gioui.org v0.1.1-0.20230719075427-babe7a292be0

# edit cmd_test.go, use old NewTheme(gofont.Collection()) line

$ goimports -w .
$ go test -bench=.
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
BenchmarkLayout-2         126622             10099 ns/op
PASS
ok      benchGiochange  1.382s
$ go test -bench=.
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
BenchmarkLayout-2          97738             10645 ns/op
PASS
ok      benchGiochange  1.145s


On 10/11/23, fgergo@gmail.com <fgergo@gmail.com> wrote:
> At the moment I'm not sure if I can send simulated events to receive
> only channel app.Window.Events() ?
>
> Is there a separate mechanism maybe?
>
> thanks!
>
>
> On 10/10/23, fgergo@gmail.com <fgergo@gmail.com> wrote:
>> Thanks!
>>
>> First every frame material.NewTheme() was called, the performance was
>> a lot worse. I realised that before looking for the 43c47f0 and before
>> sending the first email. (This 25% reduction is only with 1 NewTheme()
>> call.
>>
>> Today I realized I did not even measure rendering time (iiuc.
>> e.Frame(gtx.Ops) calls) only the layouting calls. So 25% penalty is
>> only for layouting calls.
>> Now I measure e.Frame(gtx.Ops) calls separately and I see ~25-30%
>> penalty for rendering as with 43c47f0 .
>>
>> No explicit calls to text.NewShaper() afaict.
>>
>> I'll try to make a useful a reproducer.
>>
>> thanks,
>> Gergo
>>
>>
>> On 10/10/23, Egon Elbre <egonelbre@gmail.com> wrote:
>>> It's most likely related to the typesetting changes, however AFAIK,
>>> it shouldn't impact the performance that much as long as the caches
>>> are properly used.
>>>
>>> Make sure that you are not recreating the theme and shaper every frame.
>>> i.e. `material.NewTheme` and `text.NewShaper` should not be called every
>>> frame.
>>>
>>> Other than that, I don't have a good guess what's going wrong.
>>>
>>> If you can create a small reproducer that also has this problem then
>>> that would be ideal.
>>>
>>> + Egon
>>>
>>> On Mon, Oct 9, 2023 at 9:03 PM <fgergo@gmail.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>>  Gioui is a huge help to test new ideas on different platforms, thanks
>>>> to everybody for gio!
>>>>
>>>> In one of my experiments I've been using an earlier version (commit
>>>> 5f818bc5e7f9d4) and recently I updated to a recent version and
>>>> realized both on old desktop (amd64, linux, X) and on slower android
>>>> phone my experiment became a bit sluggish. At the moment I can only
>>>> test my framerate only manually.
>>>>
>>>> I bisected to commit 43c47f08835cbc3db , but the many changes included
>>>> in this commit are too much for me to dig further by hand. (There are
>>>> a lot of changes to github.com/go-text/typesetting as well.)
>>>>
>>>> On a pc a frame with
>>>> commit babe7a292be0ca0 takes about ~7ms to render
>>>> commit 43c47f08835cbc3db takes ~9ms.
>>>>
>>>> On an old android phone a frame with
>>>> commit babe7a292be0ca0 takes about ~15ms to render
>>>> commit 43c47f08835cbc3db takes ~19ms.
>>>>
>>>> Sorry I can't provide more info.
>>>>
>>>> Do you maybe have a suspected change?
>>>>
>>>> Thanks,
>>>> Gergely
>>>
>>
>
Details
Message ID
<CANtNKfo5NKPoj0hKoPSWVBJHPjFES8O3Tpx=rCsS7Zckcn3AaA@mail.gmail.com>
In-Reply-To
<CA+ctqroneS2MMm8BJ0LVPDC20JVVrwAKXEDBdydExDE=i5du6Q@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
Note your benchmark is missing a b.Reset() so the result won't be accurate,
I'm getting this performance on M1:

```
goos: darwin
goarch: arm64
pkg: github.com/egonelbre/expgio/benchmark/layout
          │ babe7a2.log │            43c47f0.log             │
  main.log            │
          │   sec/op    │   sec/op     vs base               │
sec/op     vs base          │
Layout-10   968.5n ± 3%   995.6n ± 3%  +2.80% (p=0.004 n=10)   959.3n
± 9%  ~ (p=0.782 n=10)
```

So, there does seem to be a performance drop and increase, but it's around 3%.

So it could be that the b.Reset() missing ends up causing a
significant performance difference.
Please rerun this version of the benchmark:

```
func BenchmarkLayout(b *testing.B) {
    t := material.NewTheme() // uncomment to use with commit 43c47f0
    //t := material.NewTheme(gofont.Collection()) // uncomment to use
with commit babe7a2
    l := material.Label(t, 10, "abcdefghijklmnopqrstuvwxyz")
    gtx := layout.NewContext(&op.Ops{}, system.FrameEvent{})

    b.ResetTimer()
    for n := 0; n < b.N; n++ {
        l.Layout(gtx)
    }
}
```

With:
```
go test -bench . -count 10 | tee <commithash>.log
```

Then compare the results with `benchstat <a> <b> <c>`
(https://pkg.go.dev/golang.org/x/perf/cmd/benchstat)

This approach allows us to eliminate some noise and make sure that
we're indeed seeing such a significant slowdown.

Also please run the following and upload/share the `cpu.pprof` file somehow:

```
go test -bench . -benchtime 30s -cpuprofile cpu.pprof
```

There definitely could be a slowdown somewhere, but I'm not sure where.
The above should help pinpoint the issue and see the exact effect.

+ Egon

On Fri, Oct 20, 2023 at 4:55 PM <fgergo@gmail.com> wrote:
>
> I got distracted.
> On my oldandsilent X on linux the following repro with commit babe7a2
> is slower by 30% (or 50%, depending how you're looking at it) compared
> to with commit 43c47f0 .
>
> cheers,
> Gergo
>
> $ cat changeToCommit.sh
> #!/bin/sh
> # 43c47f0 slow commit -- material.NewTheme(gofont.Collection())
> # babe7a2 latest fast commit -- material.NewTheme(gofont.Collection())
>
> if [ $# -ne 1 ]; then
>         echo "usage: $0 commithash"
>         echo changing to 43c47f0
>         ./$0 43c47f0
>         exit 0
> fi
>
> rm -f go.mod go.sum
> go mod init benchGiochange
> go get gioui.org@$1
> go mod tidy
>
> $ cat cmd_test.go
> package benchGiochange
>
> import (
>         "sync"
>         "testing"
>
>         "gioui.org/io/system"
>         "gioui.org/layout"
>         "gioui.org/op"
>         "gioui.org/widget/material"
> )
>
> var once sync.Once
>
> var t *material.Theme
> var l material.LabelStyle
> var gtx layout.Context
>
> func setup() {
>         t = material.NewTheme() // uncomment to use with commit 43c47f0
>         //      t = material.NewTheme(gofont.Collection()) //
> uncomment to use with commit babe7a2
>
>         l = material.Label(t, 10, "abcdefghijklmnopqrstuvwxyz")
>         gtx = layout.NewContext(&op.Ops{}, system.FrameEvent{})
> }
>
> func BenchmarkLayout(b *testing.B) {
>         once.Do(setup)
>
>         for n := 0; n < b.N; n++ {
>                 l.Layout(gtx)
>         }
> }
>
> $ go test -bench=.
> goos: linux
> goarch: amd64
> pkg: benchGiochange
> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> BenchmarkLayout-2         131176             15269 ns/op
> PASS
> ok      benchGiochange  2.123s
> $ go test -bench=.
> goos: linux
> goarch: amd64
> pkg: benchGiochange
> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> BenchmarkLayout-2         102066             16035 ns/op
> PASS
> ok      benchGiochange  1.758s
> $ ./changeToCommit.sh babe7a2
> go: creating new go.mod: module benchGiochange
> go: to add module requirements and sums:
>         go mod tidy
> go: added gioui.org v0.1.1-0.20230719075427-babe7a292be0
>
> # edit cmd_test.go, use old NewTheme(gofont.Collection()) line
>
> $ goimports -w .
> $ go test -bench=.
> goos: linux
> goarch: amd64
> pkg: benchGiochange
> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> BenchmarkLayout-2         126622             10099 ns/op
> PASS
> ok      benchGiochange  1.382s
> $ go test -bench=.
> goos: linux
> goarch: amd64
> pkg: benchGiochange
> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> BenchmarkLayout-2          97738             10645 ns/op
> PASS
> ok      benchGiochange  1.145s
>
>
> On 10/11/23, fgergo@gmail.com <fgergo@gmail.com> wrote:
> > At the moment I'm not sure if I can send simulated events to receive
> > only channel app.Window.Events() ?
> >
> > Is there a separate mechanism maybe?
> >
> > thanks!
> >
> >
> > On 10/10/23, fgergo@gmail.com <fgergo@gmail.com> wrote:
> >> Thanks!
> >>
> >> First every frame material.NewTheme() was called, the performance was
> >> a lot worse. I realised that before looking for the 43c47f0 and before
> >> sending the first email. (This 25% reduction is only with 1 NewTheme()
> >> call.
> >>
> >> Today I realized I did not even measure rendering time (iiuc.
> >> e.Frame(gtx.Ops) calls) only the layouting calls. So 25% penalty is
> >> only for layouting calls.
> >> Now I measure e.Frame(gtx.Ops) calls separately and I see ~25-30%
> >> penalty for rendering as with 43c47f0 .
> >>
> >> No explicit calls to text.NewShaper() afaict.
> >>
> >> I'll try to make a useful a reproducer.
> >>
> >> thanks,
> >> Gergo
> >>
> >>
> >> On 10/10/23, Egon Elbre <egonelbre@gmail.com> wrote:
> >>> It's most likely related to the typesetting changes, however AFAIK,
> >>> it shouldn't impact the performance that much as long as the caches
> >>> are properly used.
> >>>
> >>> Make sure that you are not recreating the theme and shaper every frame.
> >>> i.e. `material.NewTheme` and `text.NewShaper` should not be called every
> >>> frame.
> >>>
> >>> Other than that, I don't have a good guess what's going wrong.
> >>>
> >>> If you can create a small reproducer that also has this problem then
> >>> that would be ideal.
> >>>
> >>> + Egon
> >>>
> >>> On Mon, Oct 9, 2023 at 9:03 PM <fgergo@gmail.com> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>>  Gioui is a huge help to test new ideas on different platforms, thanks
> >>>> to everybody for gio!
> >>>>
> >>>> In one of my experiments I've been using an earlier version (commit
> >>>> 5f818bc5e7f9d4) and recently I updated to a recent version and
> >>>> realized both on old desktop (amd64, linux, X) and on slower android
> >>>> phone my experiment became a bit sluggish. At the moment I can only
> >>>> test my framerate only manually.
> >>>>
> >>>> I bisected to commit 43c47f08835cbc3db , but the many changes included
> >>>> in this commit are too much for me to dig further by hand. (There are
> >>>> a lot of changes to github.com/go-text/typesetting as well.)
> >>>>
> >>>> On a pc a frame with
> >>>> commit babe7a292be0ca0 takes about ~7ms to render
> >>>> commit 43c47f08835cbc3db takes ~9ms.
> >>>>
> >>>> On an old android phone a frame with
> >>>> commit babe7a292be0ca0 takes about ~15ms to render
> >>>> commit 43c47f08835cbc3db takes ~19ms.
> >>>>
> >>>> Sorry I can't provide more info.
> >>>>
> >>>> Do you maybe have a suspected change?
> >>>>
> >>>> Thanks,
> >>>> Gergely
> >>>
> >>
> >
Reply to thread Export thread (mbox)