~eliasnaur/gio

10 3

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

Details
Message ID
<CA+ctqroHHRUQYmmQceo60avMWnvq0fWpWz5u6QGUZZGfJQ0Jqg@mail.gmail.com>
DKIM signature
missing
Download raw message
Thanks for the detailed benchmarking instructions, this helps a lot!
Please reply if I missed something.
I still see very different numbers.
https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3

Fwiw: your benchmark with p=0.782 means according to
https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
"it's very likely the differences for this benchmark are simply due to
random chance"
I tried to run that benchmark as well, but you probably removed it.
(If I should run that as well, please share.)

Thanks a lot for your work!

cheers,
Gergo

$ cat cmd_test.go
package benchGiochange

import (
        "testing"

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

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)
        }
}
$ ./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
$ ./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
$ go test -bench . -count 10 | tee babe7a2.log
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
BenchmarkLayout-2         102739             11058 ns/op
BenchmarkLayout-2         103851             10853 ns/op
BenchmarkLayout-2         155602             11012 ns/op
BenchmarkLayout-2         136452             11813 ns/op
BenchmarkLayout-2         133518             12070 ns/op
BenchmarkLayout-2         159237             11828 ns/op
BenchmarkLayout-2         121366             10532 ns/op
BenchmarkLayout-2         109147             11122 ns/op
BenchmarkLayout-2         143758             12059 ns/op
BenchmarkLayout-2         147904             11676 ns/op
PASS
ok      benchGiochange  16.255s
$ go test -bench . -benchtime 30s -cpuprofile babe7a2.cpu.pprof
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
BenchmarkLayout-2        3206446             11869 ns/op
PASS
ok      benchGiochange  49.782s
$ ./changeToCommit.sh 43c47f0
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.20230719080151-43c47f08835c

# Edit cmd_test.go

$ go test -bench . -count 10 | tee 43c47f0.log
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
BenchmarkLayout-2          89000             13615 ns/op
BenchmarkLayout-2          95593             14283 ns/op
BenchmarkLayout-2          96690             15635 ns/op
BenchmarkLayout-2          98223             15432 ns/op
BenchmarkLayout-2         103114             16133 ns/op
BenchmarkLayout-2         130970             17090 ns/op
BenchmarkLayout-2         118478             16265 ns/op
BenchmarkLayout-2          99070             15630 ns/op
BenchmarkLayout-2         105874             17093 ns/op
BenchmarkLayout-2         122764             16051 ns/op
PASS
ok      benchGiochange  18.116s
$ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
BenchmarkLayout-2        2449099             13154 ns/op
PASS
ok      benchGiochange  47.426s
$ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof.2
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
BenchmarkLayout-2        2911257             13267 ns/op
PASS
ok      benchGiochange  51.423s
$ benchstat babe7a2.log 43c47f0.log |tee benchstat.result.txt
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
         │ babe7a2.log │             43c47f0.log              │
         │   sec/op    │    sec/op     vs base                │
Layout-2   11.40µ ± 6%   15.84µ ± 10%  +38.99% (p=0.000 n=10)



On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
> 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
>> >>>
>> >>
>> >
>

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

Details
Message ID
<CANtNKfpAUTiS-DyaWKZZLYwrnx3R-3RvKoRzKpWq_DhE+47z0g@mail.gmail.com>
In-Reply-To
<CA+ctqroHHRUQYmmQceo60avMWnvq0fWpWz5u6QGUZZGfJQ0Jqg@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
It does seem that the caching key used in text shaper is slower.
Also, can you rerun these things with this benchmark:
```
func BenchmarkLayout(b *testing.B) {
    // uncomment to use with commit 43c47f0
    t := material.NewTheme()
    shaper := text.NewShaper(text.WithCollection(gofont.Collection()))
    // uncomment to use with commit babe7a2
    // t := material.NewTheme(gofont.Collection())
    ops := &op.Ops{}

    b.ResetTimer()
    for n := 0; n < b.N; n++ {
        gtx := layout.NewContext(ops, system.FrameEvent{})
        for i := 0; i < 3; i++ {
            material.Label(t, 10, "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
            material.Label(t, 10, "1234 1234 5434 1234 41234").Layout(gtx)
        }
    }
}
```

While looking at the profile results I realized that it was still subtly wrong.
I.e. it was creating a huge single frame which contains tons of text
instead of rendering multiple frames
each with less text.

Also, let's use the same fonts to ensure there's no difference caused
by font selection.

It should help reduce the memory allocation noise that's not relevant
to this problem (probably).

> Fwiw: your benchmark with p=0.782 means according to ...

Yes, I'm aware, I was running off of battery power, hence there might
have been weirdness...
the individual results were also flipping between two values, which
can suggest either some caching
difference or allocation difference.... either way,

> I tried to run that benchmark as well, but you probably removed it.

I didn't really upload it in the first place :)

+ Egon

On Sun, Oct 22, 2023 at 5:23 PM <fgergo@gmail.com> wrote:
>
> Thanks for the detailed benchmarking instructions, this helps a lot!
> Please reply if I missed something.
> I still see very different numbers.
> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
>
> Fwiw: your benchmark with p=0.782 means according to
> https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
> "it's very likely the differences for this benchmark are simply due to
> random chance"
> I tried to run that benchmark as well, but you probably removed it.
> (If I should run that as well, please share.)
>
> Thanks a lot for your work!
>
> cheers,
> Gergo
>
> $ cat cmd_test.go
> package benchGiochange
>
> import (
>         "testing"
>
>         "gioui.org/font/gofont"
>         "gioui.org/io/system"
>         "gioui.org/layout"
>         "gioui.org/op"
>         "gioui.org/widget/material"
> )
>
> 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)
>         }
> }
> $ ./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
> $ ./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
> $ go test -bench . -count 10 | tee babe7a2.log
> goos: linux
> goarch: amd64
> pkg: benchGiochange
> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> BenchmarkLayout-2         102739             11058 ns/op
> BenchmarkLayout-2         103851             10853 ns/op
> BenchmarkLayout-2         155602             11012 ns/op
> BenchmarkLayout-2         136452             11813 ns/op
> BenchmarkLayout-2         133518             12070 ns/op
> BenchmarkLayout-2         159237             11828 ns/op
> BenchmarkLayout-2         121366             10532 ns/op
> BenchmarkLayout-2         109147             11122 ns/op
> BenchmarkLayout-2         143758             12059 ns/op
> BenchmarkLayout-2         147904             11676 ns/op
> PASS
> ok      benchGiochange  16.255s
> $ go test -bench . -benchtime 30s -cpuprofile babe7a2.cpu.pprof
> goos: linux
> goarch: amd64
> pkg: benchGiochange
> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> BenchmarkLayout-2        3206446             11869 ns/op
> PASS
> ok      benchGiochange  49.782s
> $ ./changeToCommit.sh 43c47f0
> 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.20230719080151-43c47f08835c
>
> # Edit cmd_test.go
>
> $ go test -bench . -count 10 | tee 43c47f0.log
> goos: linux
> goarch: amd64
> pkg: benchGiochange
> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> BenchmarkLayout-2          89000             13615 ns/op
> BenchmarkLayout-2          95593             14283 ns/op
> BenchmarkLayout-2          96690             15635 ns/op
> BenchmarkLayout-2          98223             15432 ns/op
> BenchmarkLayout-2         103114             16133 ns/op
> BenchmarkLayout-2         130970             17090 ns/op
> BenchmarkLayout-2         118478             16265 ns/op
> BenchmarkLayout-2          99070             15630 ns/op
> BenchmarkLayout-2         105874             17093 ns/op
> BenchmarkLayout-2         122764             16051 ns/op
> PASS
> ok      benchGiochange  18.116s
> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof
> goos: linux
> goarch: amd64
> pkg: benchGiochange
> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> BenchmarkLayout-2        2449099             13154 ns/op
> PASS
> ok      benchGiochange  47.426s
> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof.2
> goos: linux
> goarch: amd64
> pkg: benchGiochange
> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> BenchmarkLayout-2        2911257             13267 ns/op
> PASS
> ok      benchGiochange  51.423s
> $ benchstat babe7a2.log 43c47f0.log |tee benchstat.result.txt
> goos: linux
> goarch: amd64
> pkg: benchGiochange
> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>          │ babe7a2.log │             43c47f0.log              │
>          │   sec/op    │    sec/op     vs base                │
> Layout-2   11.40µ ± 6%   15.84µ ± 10%  +38.99% (p=0.000 n=10)
>
>
>
> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
> > 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
> >> >>>
> >> >>
> >> >
> >

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

Details
Message ID
<CA+ctqrpbUo6zyuQRJ2wtQxRCFBjrtZ4UxQEjwru644S0e2dDVw@mail.gmail.com>
In-Reply-To
<CANtNKfpAUTiS-DyaWKZZLYwrnx3R-3RvKoRzKpWq_DhE+47z0g@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
This won't compile with 43c47f0.
$ ./changeToCommit.sh v0.2.0
go: creating new go.mod: module benchGiochange
go: to add module requirements and sums:
        go mod tidy
go: added gioui.org v0.2.0
$ go test -bench . -count 10 | tee 0.2.0.log
# benchGiochange [benchGiochange.test]
./cmd_test.go:17:2: shaper declared and not used
FAIL    benchGiochange [build failed]

Could you please point to a gioui example using shaper?

On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
> It does seem that the caching key used in text shaper is slower.
> Also, can you rerun these things with this benchmark:
> ```
> func BenchmarkLayout(b *testing.B) {
>     // uncomment to use with commit 43c47f0
>     t := material.NewTheme()
>     shaper := text.NewShaper(text.WithCollection(gofont.Collection()))
>     // uncomment to use with commit babe7a2
>     // t := material.NewTheme(gofont.Collection())
>     ops := &op.Ops{}
>
>     b.ResetTimer()
>     for n := 0; n < b.N; n++ {
>         gtx := layout.NewContext(ops, system.FrameEvent{})
>         for i := 0; i < 3; i++ {
>             material.Label(t, 10, "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
>             material.Label(t, 10, "1234 1234 5434 1234 41234").Layout(gtx)
>         }
>     }
> }
> ```
>
> While looking at the profile results I realized that it was still subtly
> wrong.
> I.e. it was creating a huge single frame which contains tons of text
> instead of rendering multiple frames
> each with less text.
>
> Also, let's use the same fonts to ensure there's no difference caused
> by font selection.
>
> It should help reduce the memory allocation noise that's not relevant
> to this problem (probably).
>
>> Fwiw: your benchmark with p=0.782 means according to ...
>
> Yes, I'm aware, I was running off of battery power, hence there might
> have been weirdness...
> the individual results were also flipping between two values, which
> can suggest either some caching
> difference or allocation difference.... either way,
>
>> I tried to run that benchmark as well, but you probably removed it.
>
> I didn't really upload it in the first place :)
>
> + Egon
>
> On Sun, Oct 22, 2023 at 5:23 PM <fgergo@gmail.com> wrote:
>>
>> Thanks for the detailed benchmarking instructions, this helps a lot!
>> Please reply if I missed something.
>> I still see very different numbers.
>> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
>>
>> Fwiw: your benchmark with p=0.782 means according to
>> https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
>> "it's very likely the differences for this benchmark are simply due to
>> random chance"
>> I tried to run that benchmark as well, but you probably removed it.
>> (If I should run that as well, please share.)
>>
>> Thanks a lot for your work!
>>
>> cheers,
>> Gergo
>>
>> $ cat cmd_test.go
>> package benchGiochange
>>
>> import (
>>         "testing"
>>
>>         "gioui.org/font/gofont"
>>         "gioui.org/io/system"
>>         "gioui.org/layout"
>>         "gioui.org/op"
>>         "gioui.org/widget/material"
>> )
>>
>> 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)
>>         }
>> }
>> $ ./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
>> $ ./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
>> $ go test -bench . -count 10 | tee babe7a2.log
>> goos: linux
>> goarch: amd64
>> pkg: benchGiochange
>> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> BenchmarkLayout-2         102739             11058 ns/op
>> BenchmarkLayout-2         103851             10853 ns/op
>> BenchmarkLayout-2         155602             11012 ns/op
>> BenchmarkLayout-2         136452             11813 ns/op
>> BenchmarkLayout-2         133518             12070 ns/op
>> BenchmarkLayout-2         159237             11828 ns/op
>> BenchmarkLayout-2         121366             10532 ns/op
>> BenchmarkLayout-2         109147             11122 ns/op
>> BenchmarkLayout-2         143758             12059 ns/op
>> BenchmarkLayout-2         147904             11676 ns/op
>> PASS
>> ok      benchGiochange  16.255s
>> $ go test -bench . -benchtime 30s -cpuprofile babe7a2.cpu.pprof
>> goos: linux
>> goarch: amd64
>> pkg: benchGiochange
>> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> BenchmarkLayout-2        3206446             11869 ns/op
>> PASS
>> ok      benchGiochange  49.782s
>> $ ./changeToCommit.sh 43c47f0
>> 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.20230719080151-43c47f08835c
>>
>> # Edit cmd_test.go
>>
>> $ go test -bench . -count 10 | tee 43c47f0.log
>> goos: linux
>> goarch: amd64
>> pkg: benchGiochange
>> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> BenchmarkLayout-2          89000             13615 ns/op
>> BenchmarkLayout-2          95593             14283 ns/op
>> BenchmarkLayout-2          96690             15635 ns/op
>> BenchmarkLayout-2          98223             15432 ns/op
>> BenchmarkLayout-2         103114             16133 ns/op
>> BenchmarkLayout-2         130970             17090 ns/op
>> BenchmarkLayout-2         118478             16265 ns/op
>> BenchmarkLayout-2          99070             15630 ns/op
>> BenchmarkLayout-2         105874             17093 ns/op
>> BenchmarkLayout-2         122764             16051 ns/op
>> PASS
>> ok      benchGiochange  18.116s
>> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof
>> goos: linux
>> goarch: amd64
>> pkg: benchGiochange
>> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> BenchmarkLayout-2        2449099             13154 ns/op
>> PASS
>> ok      benchGiochange  47.426s
>> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof.2
>> goos: linux
>> goarch: amd64
>> pkg: benchGiochange
>> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> BenchmarkLayout-2        2911257             13267 ns/op
>> PASS
>> ok      benchGiochange  51.423s
>> $ benchstat babe7a2.log 43c47f0.log |tee benchstat.result.txt
>> goos: linux
>> goarch: amd64
>> pkg: benchGiochange
>> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>>          │ babe7a2.log │             43c47f0.log              │
>>          │   sec/op    │    sec/op     vs base                │
>> Layout-2   11.40µ ± 6%   15.84µ ± 10%  +38.99% (p=0.000 n=10)
>>
>>
>>
>> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
>> > 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
>> >> >>>
>> >> >>
>> >> >
>> >
>

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

Details
Message ID
<CANtNKfpTwF8U4Tth59vv_vUKUBOcejzZ_vLH2sV5FdLGZ9twPg@mail.gmail.com>
In-Reply-To
<CA+ctqrpbUo6zyuQRJ2wtQxRCFBjrtZ4UxQEjwru644S0e2dDVw@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
Ah, sorry,
I made a typo while writing the code directly in email editor, this
should work now:

```
func BenchmarkLayout(b *testing.B) {
    // uncomment to use with commit 43c47f0
    t := material.NewTheme()
    t.Shaper = text.NewShaper(text.WithCollection(gofont.Collection()))
    // uncomment to use with commit babe7a2
    // t := material.NewTheme(gofont.Collection())
    ops := &op.Ops{}

    b.ResetTimer()
    for n := 0; n < b.N; n++ {
        gtx := layout.NewContext(ops, system.FrameEvent{})
        for i := 0; i < 10; i++ {
            material.Label(t, 10, "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
            material.Label(t, 10, "oifajmorfj983 4mroaermfnkli").Layout(gtx)
            material.Label(t, 10, "1234 1234 5434 1234 41234").Layout(gtx)
        }
    }
}
```

On Mon, Oct 23, 2023 at 1:54 AM <fgergo@gmail.com> wrote:
>
> This won't compile with 43c47f0.
> $ ./changeToCommit.sh v0.2.0
> go: creating new go.mod: module benchGiochange
> go: to add module requirements and sums:
>         go mod tidy
> go: added gioui.org v0.2.0
> $ go test -bench . -count 10 | tee 0.2.0.log
> # benchGiochange [benchGiochange.test]
> ./cmd_test.go:17:2: shaper declared and not used
> FAIL    benchGiochange [build failed]
>
> Could you please point to a gioui example using shaper?
>
> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
> > It does seem that the caching key used in text shaper is slower.
> > Also, can you rerun these things with this benchmark:
> > ```
> > func BenchmarkLayout(b *testing.B) {
> >     // uncomment to use with commit 43c47f0
> >     t := material.NewTheme()
> >     shaper := text.NewShaper(text.WithCollection(gofont.Collection()))
> >     // uncomment to use with commit babe7a2
> >     // t := material.NewTheme(gofont.Collection())
> >     ops := &op.Ops{}
> >
> >     b.ResetTimer()
> >     for n := 0; n < b.N; n++ {
> >         gtx := layout.NewContext(ops, system.FrameEvent{})
> >         for i := 0; i < 3; i++ {
> >             material.Label(t, 10, "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
> >             material.Label(t, 10, "1234 1234 5434 1234 41234").Layout(gtx)
> >         }
> >     }
> > }
> > ```
> >
> > While looking at the profile results I realized that it was still subtly
> > wrong.
> > I.e. it was creating a huge single frame which contains tons of text
> > instead of rendering multiple frames
> > each with less text.
> >
> > Also, let's use the same fonts to ensure there's no difference caused
> > by font selection.
> >
> > It should help reduce the memory allocation noise that's not relevant
> > to this problem (probably).
> >
> >> Fwiw: your benchmark with p=0.782 means according to ...
> >
> > Yes, I'm aware, I was running off of battery power, hence there might
> > have been weirdness...
> > the individual results were also flipping between two values, which
> > can suggest either some caching
> > difference or allocation difference.... either way,
> >
> >> I tried to run that benchmark as well, but you probably removed it.
> >
> > I didn't really upload it in the first place :)
> >
> > + Egon
> >
> > On Sun, Oct 22, 2023 at 5:23 PM <fgergo@gmail.com> wrote:
> >>
> >> Thanks for the detailed benchmarking instructions, this helps a lot!
> >> Please reply if I missed something.
> >> I still see very different numbers.
> >> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
> >>
> >> Fwiw: your benchmark with p=0.782 means according to
> >> https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
> >> "it's very likely the differences for this benchmark are simply due to
> >> random chance"
> >> I tried to run that benchmark as well, but you probably removed it.
> >> (If I should run that as well, please share.)
> >>
> >> Thanks a lot for your work!
> >>
> >> cheers,
> >> Gergo
> >>
> >> $ cat cmd_test.go
> >> package benchGiochange
> >>
> >> import (
> >>         "testing"
> >>
> >>         "gioui.org/font/gofont"
> >>         "gioui.org/io/system"
> >>         "gioui.org/layout"
> >>         "gioui.org/op"
> >>         "gioui.org/widget/material"
> >> )
> >>
> >> 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)
> >>         }
> >> }
> >> $ ./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
> >> $ ./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
> >> $ go test -bench . -count 10 | tee babe7a2.log
> >> goos: linux
> >> goarch: amd64
> >> pkg: benchGiochange
> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >> BenchmarkLayout-2         102739             11058 ns/op
> >> BenchmarkLayout-2         103851             10853 ns/op
> >> BenchmarkLayout-2         155602             11012 ns/op
> >> BenchmarkLayout-2         136452             11813 ns/op
> >> BenchmarkLayout-2         133518             12070 ns/op
> >> BenchmarkLayout-2         159237             11828 ns/op
> >> BenchmarkLayout-2         121366             10532 ns/op
> >> BenchmarkLayout-2         109147             11122 ns/op
> >> BenchmarkLayout-2         143758             12059 ns/op
> >> BenchmarkLayout-2         147904             11676 ns/op
> >> PASS
> >> ok      benchGiochange  16.255s
> >> $ go test -bench . -benchtime 30s -cpuprofile babe7a2.cpu.pprof
> >> goos: linux
> >> goarch: amd64
> >> pkg: benchGiochange
> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >> BenchmarkLayout-2        3206446             11869 ns/op
> >> PASS
> >> ok      benchGiochange  49.782s
> >> $ ./changeToCommit.sh 43c47f0
> >> 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.20230719080151-43c47f08835c
> >>
> >> # Edit cmd_test.go
> >>
> >> $ go test -bench . -count 10 | tee 43c47f0.log
> >> goos: linux
> >> goarch: amd64
> >> pkg: benchGiochange
> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >> BenchmarkLayout-2          89000             13615 ns/op
> >> BenchmarkLayout-2          95593             14283 ns/op
> >> BenchmarkLayout-2          96690             15635 ns/op
> >> BenchmarkLayout-2          98223             15432 ns/op
> >> BenchmarkLayout-2         103114             16133 ns/op
> >> BenchmarkLayout-2         130970             17090 ns/op
> >> BenchmarkLayout-2         118478             16265 ns/op
> >> BenchmarkLayout-2          99070             15630 ns/op
> >> BenchmarkLayout-2         105874             17093 ns/op
> >> BenchmarkLayout-2         122764             16051 ns/op
> >> PASS
> >> ok      benchGiochange  18.116s
> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof
> >> goos: linux
> >> goarch: amd64
> >> pkg: benchGiochange
> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >> BenchmarkLayout-2        2449099             13154 ns/op
> >> PASS
> >> ok      benchGiochange  47.426s
> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof.2
> >> goos: linux
> >> goarch: amd64
> >> pkg: benchGiochange
> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >> BenchmarkLayout-2        2911257             13267 ns/op
> >> PASS
> >> ok      benchGiochange  51.423s
> >> $ benchstat babe7a2.log 43c47f0.log |tee benchstat.result.txt
> >> goos: linux
> >> goarch: amd64
> >> pkg: benchGiochange
> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >>          │ babe7a2.log │             43c47f0.log              │
> >>          │   sec/op    │    sec/op     vs base                │
> >> Layout-2   11.40µ ± 6%   15.84µ ± 10%  +38.99% (p=0.000 n=10)
> >>
> >>
> >>
> >> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
> >> > 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
> >> >> >>>
> >> >> >>
> >> >> >
> >> >
> >

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

Details
Message ID
<CA+ctqrpVgruMygoAPDEB-gA1n8TdtHugMx4P1Nwt_Qd2vQK7Lw@mail.gmail.com>
In-Reply-To
<CANtNKfpTwF8U4Tth59vv_vUKUBOcejzZ_vLH2sV5FdLGZ9twPg@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
Thanks!
Uploaded all files to same google drive share. (Previous files: arch/):
https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3


On 10/23/23, Egon Elbre <egonelbre@gmail.com> wrote:
> Ah, sorry,
> I made a typo while writing the code directly in email editor, this
> should work now:
>
> ```
> func BenchmarkLayout(b *testing.B) {
>     // uncomment to use with commit 43c47f0
>     t := material.NewTheme()
>     t.Shaper = text.NewShaper(text.WithCollection(gofont.Collection()))
>     // uncomment to use with commit babe7a2
>     // t := material.NewTheme(gofont.Collection())
>     ops := &op.Ops{}
>
>     b.ResetTimer()
>     for n := 0; n < b.N; n++ {
>         gtx := layout.NewContext(ops, system.FrameEvent{})
>         for i := 0; i < 10; i++ {
>             material.Label(t, 10, "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
>             material.Label(t, 10, "oifajmorfj983
> 4mroaermfnkli").Layout(gtx)
>             material.Label(t, 10, "1234 1234 5434 1234 41234").Layout(gtx)
>         }
>     }
> }
> ```
>
> On Mon, Oct 23, 2023 at 1:54 AM <fgergo@gmail.com> wrote:
>>
>> This won't compile with 43c47f0.
>> $ ./changeToCommit.sh v0.2.0
>> go: creating new go.mod: module benchGiochange
>> go: to add module requirements and sums:
>>         go mod tidy
>> go: added gioui.org v0.2.0
>> $ go test -bench . -count 10 | tee 0.2.0.log
>> # benchGiochange [benchGiochange.test]
>> ./cmd_test.go:17:2: shaper declared and not used
>> FAIL    benchGiochange [build failed]
>>
>> Could you please point to a gioui example using shaper?
>>
>> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
>> > It does seem that the caching key used in text shaper is slower.
>> > Also, can you rerun these things with this benchmark:
>> > ```
>> > func BenchmarkLayout(b *testing.B) {
>> >     // uncomment to use with commit 43c47f0
>> >     t := material.NewTheme()
>> >     shaper := text.NewShaper(text.WithCollection(gofont.Collection()))
>> >     // uncomment to use with commit babe7a2
>> >     // t := material.NewTheme(gofont.Collection())
>> >     ops := &op.Ops{}
>> >
>> >     b.ResetTimer()
>> >     for n := 0; n < b.N; n++ {
>> >         gtx := layout.NewContext(ops, system.FrameEvent{})
>> >         for i := 0; i < 3; i++ {
>> >             material.Label(t, 10,
>> > "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
>> >             material.Label(t, 10, "1234 1234 5434 1234
>> > 41234").Layout(gtx)
>> >         }
>> >     }
>> > }
>> > ```
>> >
>> > While looking at the profile results I realized that it was still
>> > subtly
>> > wrong.
>> > I.e. it was creating a huge single frame which contains tons of text
>> > instead of rendering multiple frames
>> > each with less text.
>> >
>> > Also, let's use the same fonts to ensure there's no difference caused
>> > by font selection.
>> >
>> > It should help reduce the memory allocation noise that's not relevant
>> > to this problem (probably).
>> >
>> >> Fwiw: your benchmark with p=0.782 means according to ...
>> >
>> > Yes, I'm aware, I was running off of battery power, hence there might
>> > have been weirdness...
>> > the individual results were also flipping between two values, which
>> > can suggest either some caching
>> > difference or allocation difference.... either way,
>> >
>> >> I tried to run that benchmark as well, but you probably removed it.
>> >
>> > I didn't really upload it in the first place :)
>> >
>> > + Egon
>> >
>> > On Sun, Oct 22, 2023 at 5:23 PM <fgergo@gmail.com> wrote:
>> >>
>> >> Thanks for the detailed benchmarking instructions, this helps a lot!
>> >> Please reply if I missed something.
>> >> I still see very different numbers.
>> >> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
>> >>
>> >> Fwiw: your benchmark with p=0.782 means according to
>> >> https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
>> >> "it's very likely the differences for this benchmark are simply due to
>> >> random chance"
>> >> I tried to run that benchmark as well, but you probably removed it.
>> >> (If I should run that as well, please share.)
>> >>
>> >> Thanks a lot for your work!
>> >>
>> >> cheers,
>> >> Gergo
>> >>
>> >> $ cat cmd_test.go
>> >> package benchGiochange
>> >>
>> >> import (
>> >>         "testing"
>> >>
>> >>         "gioui.org/font/gofont"
>> >>         "gioui.org/io/system"
>> >>         "gioui.org/layout"
>> >>         "gioui.org/op"
>> >>         "gioui.org/widget/material"
>> >> )
>> >>
>> >> 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)
>> >>         }
>> >> }
>> >> $ ./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
>> >> $ ./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
>> >> $ go test -bench . -count 10 | tee babe7a2.log
>> >> goos: linux
>> >> goarch: amd64
>> >> pkg: benchGiochange
>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >> BenchmarkLayout-2         102739             11058 ns/op
>> >> BenchmarkLayout-2         103851             10853 ns/op
>> >> BenchmarkLayout-2         155602             11012 ns/op
>> >> BenchmarkLayout-2         136452             11813 ns/op
>> >> BenchmarkLayout-2         133518             12070 ns/op
>> >> BenchmarkLayout-2         159237             11828 ns/op
>> >> BenchmarkLayout-2         121366             10532 ns/op
>> >> BenchmarkLayout-2         109147             11122 ns/op
>> >> BenchmarkLayout-2         143758             12059 ns/op
>> >> BenchmarkLayout-2         147904             11676 ns/op
>> >> PASS
>> >> ok      benchGiochange  16.255s
>> >> $ go test -bench . -benchtime 30s -cpuprofile babe7a2.cpu.pprof
>> >> goos: linux
>> >> goarch: amd64
>> >> pkg: benchGiochange
>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >> BenchmarkLayout-2        3206446             11869 ns/op
>> >> PASS
>> >> ok      benchGiochange  49.782s
>> >> $ ./changeToCommit.sh 43c47f0
>> >> 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.20230719080151-43c47f08835c
>> >>
>> >> # Edit cmd_test.go
>> >>
>> >> $ go test -bench . -count 10 | tee 43c47f0.log
>> >> goos: linux
>> >> goarch: amd64
>> >> pkg: benchGiochange
>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >> BenchmarkLayout-2          89000             13615 ns/op
>> >> BenchmarkLayout-2          95593             14283 ns/op
>> >> BenchmarkLayout-2          96690             15635 ns/op
>> >> BenchmarkLayout-2          98223             15432 ns/op
>> >> BenchmarkLayout-2         103114             16133 ns/op
>> >> BenchmarkLayout-2         130970             17090 ns/op
>> >> BenchmarkLayout-2         118478             16265 ns/op
>> >> BenchmarkLayout-2          99070             15630 ns/op
>> >> BenchmarkLayout-2         105874             17093 ns/op
>> >> BenchmarkLayout-2         122764             16051 ns/op
>> >> PASS
>> >> ok      benchGiochange  18.116s
>> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof
>> >> goos: linux
>> >> goarch: amd64
>> >> pkg: benchGiochange
>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >> BenchmarkLayout-2        2449099             13154 ns/op
>> >> PASS
>> >> ok      benchGiochange  47.426s
>> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof.2
>> >> goos: linux
>> >> goarch: amd64
>> >> pkg: benchGiochange
>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >> BenchmarkLayout-2        2911257             13267 ns/op
>> >> PASS
>> >> ok      benchGiochange  51.423s
>> >> $ benchstat babe7a2.log 43c47f0.log |tee benchstat.result.txt
>> >> goos: linux
>> >> goarch: amd64
>> >> pkg: benchGiochange
>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >>          │ babe7a2.log │             43c47f0.log              │
>> >>          │   sec/op    │    sec/op     vs base                │
>> >> Layout-2   11.40µ ± 6%   15.84µ ± 10%  +38.99% (p=0.000 n=10)
>> >>
>> >>
>> >>
>> >> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
>> >> > 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
>> >> >> >>>
>> >> >> >>
>> >> >> >
>> >> >
>> >
>

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

Details
Message ID
<CA+ctqroroTH-JhmRWL-3B_T=LPb6PoAncQGNy=1ND7Q4FU_oFQ@mail.gmail.com>
In-Reply-To
<CA+ctqrpVgruMygoAPDEB-gA1n8TdtHugMx4P1Nwt_Qd2vQK7Lw@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
Same share, under win/ the results are for windows10.
benchstat reports ~3%.


On 10/23/23, fgergo@gmail.com <fgergo@gmail.com> wrote:
> Thanks!
> Uploaded all files to same google drive share. (Previous files: arch/):
> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
>
>
> On 10/23/23, Egon Elbre <egonelbre@gmail.com> wrote:
>> Ah, sorry,
>> I made a typo while writing the code directly in email editor, this
>> should work now:
>>
>> ```
>> func BenchmarkLayout(b *testing.B) {
>>     // uncomment to use with commit 43c47f0
>>     t := material.NewTheme()
>>     t.Shaper = text.NewShaper(text.WithCollection(gofont.Collection()))
>>     // uncomment to use with commit babe7a2
>>     // t := material.NewTheme(gofont.Collection())
>>     ops := &op.Ops{}
>>
>>     b.ResetTimer()
>>     for n := 0; n < b.N; n++ {
>>         gtx := layout.NewContext(ops, system.FrameEvent{})
>>         for i := 0; i < 10; i++ {
>>             material.Label(t, 10,
>> "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
>>             material.Label(t, 10, "oifajmorfj983
>> 4mroaermfnkli").Layout(gtx)
>>             material.Label(t, 10, "1234 1234 5434 1234
>> 41234").Layout(gtx)
>>         }
>>     }
>> }
>> ```
>>
>> On Mon, Oct 23, 2023 at 1:54 AM <fgergo@gmail.com> wrote:
>>>
>>> This won't compile with 43c47f0.
>>> $ ./changeToCommit.sh v0.2.0
>>> go: creating new go.mod: module benchGiochange
>>> go: to add module requirements and sums:
>>>         go mod tidy
>>> go: added gioui.org v0.2.0
>>> $ go test -bench . -count 10 | tee 0.2.0.log
>>> # benchGiochange [benchGiochange.test]
>>> ./cmd_test.go:17:2: shaper declared and not used
>>> FAIL    benchGiochange [build failed]
>>>
>>> Could you please point to a gioui example using shaper?
>>>
>>> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
>>> > It does seem that the caching key used in text shaper is slower.
>>> > Also, can you rerun these things with this benchmark:
>>> > ```
>>> > func BenchmarkLayout(b *testing.B) {
>>> >     // uncomment to use with commit 43c47f0
>>> >     t := material.NewTheme()
>>> >     shaper := text.NewShaper(text.WithCollection(gofont.Collection()))
>>> >     // uncomment to use with commit babe7a2
>>> >     // t := material.NewTheme(gofont.Collection())
>>> >     ops := &op.Ops{}
>>> >
>>> >     b.ResetTimer()
>>> >     for n := 0; n < b.N; n++ {
>>> >         gtx := layout.NewContext(ops, system.FrameEvent{})
>>> >         for i := 0; i < 3; i++ {
>>> >             material.Label(t, 10,
>>> > "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
>>> >             material.Label(t, 10, "1234 1234 5434 1234
>>> > 41234").Layout(gtx)
>>> >         }
>>> >     }
>>> > }
>>> > ```
>>> >
>>> > While looking at the profile results I realized that it was still
>>> > subtly
>>> > wrong.
>>> > I.e. it was creating a huge single frame which contains tons of text
>>> > instead of rendering multiple frames
>>> > each with less text.
>>> >
>>> > Also, let's use the same fonts to ensure there's no difference caused
>>> > by font selection.
>>> >
>>> > It should help reduce the memory allocation noise that's not relevant
>>> > to this problem (probably).
>>> >
>>> >> Fwiw: your benchmark with p=0.782 means according to ...
>>> >
>>> > Yes, I'm aware, I was running off of battery power, hence there might
>>> > have been weirdness...
>>> > the individual results were also flipping between two values, which
>>> > can suggest either some caching
>>> > difference or allocation difference.... either way,
>>> >
>>> >> I tried to run that benchmark as well, but you probably removed it.
>>> >
>>> > I didn't really upload it in the first place :)
>>> >
>>> > + Egon
>>> >
>>> > On Sun, Oct 22, 2023 at 5:23 PM <fgergo@gmail.com> wrote:
>>> >>
>>> >> Thanks for the detailed benchmarking instructions, this helps a lot!
>>> >> Please reply if I missed something.
>>> >> I still see very different numbers.
>>> >> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
>>> >>
>>> >> Fwiw: your benchmark with p=0.782 means according to
>>> >> https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
>>> >> "it's very likely the differences for this benchmark are simply due
>>> >> to
>>> >> random chance"
>>> >> I tried to run that benchmark as well, but you probably removed it.
>>> >> (If I should run that as well, please share.)
>>> >>
>>> >> Thanks a lot for your work!
>>> >>
>>> >> cheers,
>>> >> Gergo
>>> >>
>>> >> $ cat cmd_test.go
>>> >> package benchGiochange
>>> >>
>>> >> import (
>>> >>         "testing"
>>> >>
>>> >>         "gioui.org/font/gofont"
>>> >>         "gioui.org/io/system"
>>> >>         "gioui.org/layout"
>>> >>         "gioui.org/op"
>>> >>         "gioui.org/widget/material"
>>> >> )
>>> >>
>>> >> 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)
>>> >>         }
>>> >> }
>>> >> $ ./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
>>> >> $ ./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
>>> >> $ go test -bench . -count 10 | tee babe7a2.log
>>> >> goos: linux
>>> >> goarch: amd64
>>> >> pkg: benchGiochange
>>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>>> >> BenchmarkLayout-2         102739             11058 ns/op
>>> >> BenchmarkLayout-2         103851             10853 ns/op
>>> >> BenchmarkLayout-2         155602             11012 ns/op
>>> >> BenchmarkLayout-2         136452             11813 ns/op
>>> >> BenchmarkLayout-2         133518             12070 ns/op
>>> >> BenchmarkLayout-2         159237             11828 ns/op
>>> >> BenchmarkLayout-2         121366             10532 ns/op
>>> >> BenchmarkLayout-2         109147             11122 ns/op
>>> >> BenchmarkLayout-2         143758             12059 ns/op
>>> >> BenchmarkLayout-2         147904             11676 ns/op
>>> >> PASS
>>> >> ok      benchGiochange  16.255s
>>> >> $ go test -bench . -benchtime 30s -cpuprofile babe7a2.cpu.pprof
>>> >> goos: linux
>>> >> goarch: amd64
>>> >> pkg: benchGiochange
>>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>>> >> BenchmarkLayout-2        3206446             11869 ns/op
>>> >> PASS
>>> >> ok      benchGiochange  49.782s
>>> >> $ ./changeToCommit.sh 43c47f0
>>> >> 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.20230719080151-43c47f08835c
>>> >>
>>> >> # Edit cmd_test.go
>>> >>
>>> >> $ go test -bench . -count 10 | tee 43c47f0.log
>>> >> goos: linux
>>> >> goarch: amd64
>>> >> pkg: benchGiochange
>>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>>> >> BenchmarkLayout-2          89000             13615 ns/op
>>> >> BenchmarkLayout-2          95593             14283 ns/op
>>> >> BenchmarkLayout-2          96690             15635 ns/op
>>> >> BenchmarkLayout-2          98223             15432 ns/op
>>> >> BenchmarkLayout-2         103114             16133 ns/op
>>> >> BenchmarkLayout-2         130970             17090 ns/op
>>> >> BenchmarkLayout-2         118478             16265 ns/op
>>> >> BenchmarkLayout-2          99070             15630 ns/op
>>> >> BenchmarkLayout-2         105874             17093 ns/op
>>> >> BenchmarkLayout-2         122764             16051 ns/op
>>> >> PASS
>>> >> ok      benchGiochange  18.116s
>>> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof
>>> >> goos: linux
>>> >> goarch: amd64
>>> >> pkg: benchGiochange
>>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>>> >> BenchmarkLayout-2        2449099             13154 ns/op
>>> >> PASS
>>> >> ok      benchGiochange  47.426s
>>> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof.2
>>> >> goos: linux
>>> >> goarch: amd64
>>> >> pkg: benchGiochange
>>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>>> >> BenchmarkLayout-2        2911257             13267 ns/op
>>> >> PASS
>>> >> ok      benchGiochange  51.423s
>>> >> $ benchstat babe7a2.log 43c47f0.log |tee benchstat.result.txt
>>> >> goos: linux
>>> >> goarch: amd64
>>> >> pkg: benchGiochange
>>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>>> >>          │ babe7a2.log │             43c47f0.log              │
>>> >>          │   sec/op    │    sec/op     vs base                │
>>> >> Layout-2   11.40µ ± 6%   15.84µ ± 10%  +38.99% (p=0.000 n=10)
>>> >>
>>> >>
>>> >>
>>> >> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
>>> >> > 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
>>> >> >> >>>
>>> >> >> >>
>>> >> >> >
>>> >> >
>>> >
>>
>

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

Details
Message ID
<CANtNKfqza2Z2AbnCzfB1nKV1vY9wAUiwB3TS66ymk5-YqHZ8Ew@mail.gmail.com>
In-Reply-To
<CA+ctqroroTH-JhmRWL-3B_T=LPb6PoAncQGNy=1ND7Q4FU_oFQ@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
So,

I sent a few patches that should improve this.
https://lists.sr.ht/~eliasnaur/gio-patches/patches/45986

They haven't been merged yet.

I'm looking where it can be further optimized.

+ Egon


On Tue, Oct 24, 2023 at 12:07 PM <fgergo@gmail.com> wrote:
>
> Same share, under win/ the results are for windows10.
> benchstat reports ~3%.
>
>
> On 10/23/23, fgergo@gmail.com <fgergo@gmail.com> wrote:
> > Thanks!
> > Uploaded all files to same google drive share. (Previous files: arch/):
> > https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
> >
> >
> > On 10/23/23, Egon Elbre <egonelbre@gmail.com> wrote:
> >> Ah, sorry,
> >> I made a typo while writing the code directly in email editor, this
> >> should work now:
> >>
> >> ```
> >> func BenchmarkLayout(b *testing.B) {
> >>     // uncomment to use with commit 43c47f0
> >>     t := material.NewTheme()
> >>     t.Shaper = text.NewShaper(text.WithCollection(gofont.Collection()))
> >>     // uncomment to use with commit babe7a2
> >>     // t := material.NewTheme(gofont.Collection())
> >>     ops := &op.Ops{}
> >>
> >>     b.ResetTimer()
> >>     for n := 0; n < b.N; n++ {
> >>         gtx := layout.NewContext(ops, system.FrameEvent{})
> >>         for i := 0; i < 10; i++ {
> >>             material.Label(t, 10,
> >> "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
> >>             material.Label(t, 10, "oifajmorfj983
> >> 4mroaermfnkli").Layout(gtx)
> >>             material.Label(t, 10, "1234 1234 5434 1234
> >> 41234").Layout(gtx)
> >>         }
> >>     }
> >> }
> >> ```
> >>
> >> On Mon, Oct 23, 2023 at 1:54 AM <fgergo@gmail.com> wrote:
> >>>
> >>> This won't compile with 43c47f0.
> >>> $ ./changeToCommit.sh v0.2.0
> >>> go: creating new go.mod: module benchGiochange
> >>> go: to add module requirements and sums:
> >>>         go mod tidy
> >>> go: added gioui.org v0.2.0
> >>> $ go test -bench . -count 10 | tee 0.2.0.log
> >>> # benchGiochange [benchGiochange.test]
> >>> ./cmd_test.go:17:2: shaper declared and not used
> >>> FAIL    benchGiochange [build failed]
> >>>
> >>> Could you please point to a gioui example using shaper?
> >>>
> >>> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
> >>> > It does seem that the caching key used in text shaper is slower.
> >>> > Also, can you rerun these things with this benchmark:
> >>> > ```
> >>> > func BenchmarkLayout(b *testing.B) {
> >>> >     // uncomment to use with commit 43c47f0
> >>> >     t := material.NewTheme()
> >>> >     shaper := text.NewShaper(text.WithCollection(gofont.Collection()))
> >>> >     // uncomment to use with commit babe7a2
> >>> >     // t := material.NewTheme(gofont.Collection())
> >>> >     ops := &op.Ops{}
> >>> >
> >>> >     b.ResetTimer()
> >>> >     for n := 0; n < b.N; n++ {
> >>> >         gtx := layout.NewContext(ops, system.FrameEvent{})
> >>> >         for i := 0; i < 3; i++ {
> >>> >             material.Label(t, 10,
> >>> > "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
> >>> >             material.Label(t, 10, "1234 1234 5434 1234
> >>> > 41234").Layout(gtx)
> >>> >         }
> >>> >     }
> >>> > }
> >>> > ```
> >>> >
> >>> > While looking at the profile results I realized that it was still
> >>> > subtly
> >>> > wrong.
> >>> > I.e. it was creating a huge single frame which contains tons of text
> >>> > instead of rendering multiple frames
> >>> > each with less text.
> >>> >
> >>> > Also, let's use the same fonts to ensure there's no difference caused
> >>> > by font selection.
> >>> >
> >>> > It should help reduce the memory allocation noise that's not relevant
> >>> > to this problem (probably).
> >>> >
> >>> >> Fwiw: your benchmark with p=0.782 means according to ...
> >>> >
> >>> > Yes, I'm aware, I was running off of battery power, hence there might
> >>> > have been weirdness...
> >>> > the individual results were also flipping between two values, which
> >>> > can suggest either some caching
> >>> > difference or allocation difference.... either way,
> >>> >
> >>> >> I tried to run that benchmark as well, but you probably removed it.
> >>> >
> >>> > I didn't really upload it in the first place :)
> >>> >
> >>> > + Egon
> >>> >
> >>> > On Sun, Oct 22, 2023 at 5:23 PM <fgergo@gmail.com> wrote:
> >>> >>
> >>> >> Thanks for the detailed benchmarking instructions, this helps a lot!
> >>> >> Please reply if I missed something.
> >>> >> I still see very different numbers.
> >>> >> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
> >>> >>
> >>> >> Fwiw: your benchmark with p=0.782 means according to
> >>> >> https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
> >>> >> "it's very likely the differences for this benchmark are simply due
> >>> >> to
> >>> >> random chance"
> >>> >> I tried to run that benchmark as well, but you probably removed it.
> >>> >> (If I should run that as well, please share.)
> >>> >>
> >>> >> Thanks a lot for your work!
> >>> >>
> >>> >> cheers,
> >>> >> Gergo
> >>> >>
> >>> >> $ cat cmd_test.go
> >>> >> package benchGiochange
> >>> >>
> >>> >> import (
> >>> >>         "testing"
> >>> >>
> >>> >>         "gioui.org/font/gofont"
> >>> >>         "gioui.org/io/system"
> >>> >>         "gioui.org/layout"
> >>> >>         "gioui.org/op"
> >>> >>         "gioui.org/widget/material"
> >>> >> )
> >>> >>
> >>> >> 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)
> >>> >>         }
> >>> >> }
> >>> >> $ ./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
> >>> >> $ ./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
> >>> >> $ go test -bench . -count 10 | tee babe7a2.log
> >>> >> goos: linux
> >>> >> goarch: amd64
> >>> >> pkg: benchGiochange
> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >>> >> BenchmarkLayout-2         102739             11058 ns/op
> >>> >> BenchmarkLayout-2         103851             10853 ns/op
> >>> >> BenchmarkLayout-2         155602             11012 ns/op
> >>> >> BenchmarkLayout-2         136452             11813 ns/op
> >>> >> BenchmarkLayout-2         133518             12070 ns/op
> >>> >> BenchmarkLayout-2         159237             11828 ns/op
> >>> >> BenchmarkLayout-2         121366             10532 ns/op
> >>> >> BenchmarkLayout-2         109147             11122 ns/op
> >>> >> BenchmarkLayout-2         143758             12059 ns/op
> >>> >> BenchmarkLayout-2         147904             11676 ns/op
> >>> >> PASS
> >>> >> ok      benchGiochange  16.255s
> >>> >> $ go test -bench . -benchtime 30s -cpuprofile babe7a2.cpu.pprof
> >>> >> goos: linux
> >>> >> goarch: amd64
> >>> >> pkg: benchGiochange
> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >>> >> BenchmarkLayout-2        3206446             11869 ns/op
> >>> >> PASS
> >>> >> ok      benchGiochange  49.782s
> >>> >> $ ./changeToCommit.sh 43c47f0
> >>> >> 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.20230719080151-43c47f08835c
> >>> >>
> >>> >> # Edit cmd_test.go
> >>> >>
> >>> >> $ go test -bench . -count 10 | tee 43c47f0.log
> >>> >> goos: linux
> >>> >> goarch: amd64
> >>> >> pkg: benchGiochange
> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >>> >> BenchmarkLayout-2          89000             13615 ns/op
> >>> >> BenchmarkLayout-2          95593             14283 ns/op
> >>> >> BenchmarkLayout-2          96690             15635 ns/op
> >>> >> BenchmarkLayout-2          98223             15432 ns/op
> >>> >> BenchmarkLayout-2         103114             16133 ns/op
> >>> >> BenchmarkLayout-2         130970             17090 ns/op
> >>> >> BenchmarkLayout-2         118478             16265 ns/op
> >>> >> BenchmarkLayout-2          99070             15630 ns/op
> >>> >> BenchmarkLayout-2         105874             17093 ns/op
> >>> >> BenchmarkLayout-2         122764             16051 ns/op
> >>> >> PASS
> >>> >> ok      benchGiochange  18.116s
> >>> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof
> >>> >> goos: linux
> >>> >> goarch: amd64
> >>> >> pkg: benchGiochange
> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >>> >> BenchmarkLayout-2        2449099             13154 ns/op
> >>> >> PASS
> >>> >> ok      benchGiochange  47.426s
> >>> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof.2
> >>> >> goos: linux
> >>> >> goarch: amd64
> >>> >> pkg: benchGiochange
> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >>> >> BenchmarkLayout-2        2911257             13267 ns/op
> >>> >> PASS
> >>> >> ok      benchGiochange  51.423s
> >>> >> $ benchstat babe7a2.log 43c47f0.log |tee benchstat.result.txt
> >>> >> goos: linux
> >>> >> goarch: amd64
> >>> >> pkg: benchGiochange
> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >>> >>          │ babe7a2.log │             43c47f0.log              │
> >>> >>          │   sec/op    │    sec/op     vs base                │
> >>> >> Layout-2   11.40µ ± 6%   15.84µ ± 10%  +38.99% (p=0.000 n=10)
> >>> >>
> >>> >>
> >>> >>
> >>> >> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
> >>> >> > 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
> >>> >> >> >>>
> >>> >> >> >>
> >>> >> >> >
> >>> >> >
> >>> >
> >>
> >

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

Details
Message ID
<CA+ctqrpKxS8TY6FOq=YXorEvuscVk6UFCr6+XEBZC=BMHKgqwg@mail.gmail.com>
In-Reply-To
<CANtNKfqza2Z2AbnCzfB1nKV1vY9wAUiwB3TS66ymk5-YqHZ8Ew@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
Thanks for the patches! I'll rerun all tests as soon as they are merged.

fwiw: I ran the benchmarks with the same fonts with bigger n on 2
android phones (>100% and ~40%)
termux, go1.21.3 and again on the old linux machine (~12%) and with
different fonts on linux (~20%)

The linux benchmarks show that on linux 7% of slowdown I experienced
came from using a default(?) font. Is this expected? Is there a way
without measuring the layout time to guesstimate a "fast" font?

For benchmarking I used a fairly self-contained set of scripts on
the google drive share (bench.tar).
https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3

$ tar xf bench.tar; cd bench
$ ./rundiff.sh # using the same fonts; benchmark comparison results in
benchstat*.txt files

android phone1:
# same fonts
$ cat benchstat.*|grep Layout
Layout-6                 522.5µ ± 0%   1140.1µ ± 3%  +118.18% (p=0.000 n=30)
Layout-6                 521.9µ ± 0%   1117.4µ ± 4%  +114.08% (p=0.000 n=30

android phone2:
# same fonts
$ cat benchstat.*|grep Layout
Layout-8                 184.6µ ± 0%   260.9µ ± 0%  +41.31% (p=0.000 n=100)
Layout-8                 187.8µ ± 0%   262.0µ ± 0%  +39.49% (p=0.000 n=100)

The oldandsilent amd64+Linux+X machine:
# same fonts
$ cat benchstat.*|grep Layout
Layout-2                 165.5µ ± 1%   187.6µ ± 1%  +13.36% (p=0.000 n=100)
Layout-2                 167.6µ ± 1%   188.0µ ± 1%  +12.16% (p=0.000 n=100)
Layout-2                 167.7µ ± 1%   188.2µ ± 1%  +12.22% (p=0.000 n=100)

# with different fonts:
$ cat benchstat.*|grep Layout
Layout-2                 169.4µ ± 3%   207.0µ ± 1%  +22.18% (p=0.000 n=42)
Layout-2                 174.8µ ± 3%   209.6µ ± 2%  +19.88% (p=0.000 n=42)
Layout-2                 172.3µ ± 2%   209.6µ ± 1%  +21.65% (p=0.000 n=42)

On 10/24/23, Egon Elbre <egonelbre@gmail.com> wrote:
> So,
>
> I sent a few patches that should improve this.
> https://lists.sr.ht/~eliasnaur/gio-patches/patches/45986
>
> They haven't been merged yet.
>
> I'm looking where it can be further optimized.
>
> + Egon
>
>
> On Tue, Oct 24, 2023 at 12:07 PM <fgergo@gmail.com> wrote:
>>
>> Same share, under win/ the results are for windows10.
>> benchstat reports ~3%.
>>
>>
>> On 10/23/23, fgergo@gmail.com <fgergo@gmail.com> wrote:
>> > Thanks!
>> > Uploaded all files to same google drive share. (Previous files: arch/):
>> > https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
>> >
>> >
>> > On 10/23/23, Egon Elbre <egonelbre@gmail.com> wrote:
>> >> Ah, sorry,
>> >> I made a typo while writing the code directly in email editor, this
>> >> should work now:
>> >>
>> >> ```
>> >> func BenchmarkLayout(b *testing.B) {
>> >>     // uncomment to use with commit 43c47f0
>> >>     t := material.NewTheme()
>> >>     t.Shaper =
>> >> text.NewShaper(text.WithCollection(gofont.Collection()))
>> >>     // uncomment to use with commit babe7a2
>> >>     // t := material.NewTheme(gofont.Collection())
>> >>     ops := &op.Ops{}
>> >>
>> >>     b.ResetTimer()
>> >>     for n := 0; n < b.N; n++ {
>> >>         gtx := layout.NewContext(ops, system.FrameEvent{})
>> >>         for i := 0; i < 10; i++ {
>> >>             material.Label(t, 10,
>> >> "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
>> >>             material.Label(t, 10, "oifajmorfj983
>> >> 4mroaermfnkli").Layout(gtx)
>> >>             material.Label(t, 10, "1234 1234 5434 1234
>> >> 41234").Layout(gtx)
>> >>         }
>> >>     }
>> >> }
>> >> ```
>> >>
>> >> On Mon, Oct 23, 2023 at 1:54 AM <fgergo@gmail.com> wrote:
>> >>>
>> >>> This won't compile with 43c47f0.
>> >>> $ ./changeToCommit.sh v0.2.0
>> >>> go: creating new go.mod: module benchGiochange
>> >>> go: to add module requirements and sums:
>> >>>         go mod tidy
>> >>> go: added gioui.org v0.2.0
>> >>> $ go test -bench . -count 10 | tee 0.2.0.log
>> >>> # benchGiochange [benchGiochange.test]
>> >>> ./cmd_test.go:17:2: shaper declared and not used
>> >>> FAIL    benchGiochange [build failed]
>> >>>
>> >>> Could you please point to a gioui example using shaper?
>> >>>
>> >>> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
>> >>> > It does seem that the caching key used in text shaper is slower.
>> >>> > Also, can you rerun these things with this benchmark:
>> >>> > ```
>> >>> > func BenchmarkLayout(b *testing.B) {
>> >>> >     // uncomment to use with commit 43c47f0
>> >>> >     t := material.NewTheme()
>> >>> >     shaper :=
>> >>> > text.NewShaper(text.WithCollection(gofont.Collection()))
>> >>> >     // uncomment to use with commit babe7a2
>> >>> >     // t := material.NewTheme(gofont.Collection())
>> >>> >     ops := &op.Ops{}
>> >>> >
>> >>> >     b.ResetTimer()
>> >>> >     for n := 0; n < b.N; n++ {
>> >>> >         gtx := layout.NewContext(ops, system.FrameEvent{})
>> >>> >         for i := 0; i < 3; i++ {
>> >>> >             material.Label(t, 10,
>> >>> > "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
>> >>> >             material.Label(t, 10, "1234 1234 5434 1234
>> >>> > 41234").Layout(gtx)
>> >>> >         }
>> >>> >     }
>> >>> > }
>> >>> > ```
>> >>> >
>> >>> > While looking at the profile results I realized that it was still
>> >>> > subtly
>> >>> > wrong.
>> >>> > I.e. it was creating a huge single frame which contains tons of
>> >>> > text
>> >>> > instead of rendering multiple frames
>> >>> > each with less text.
>> >>> >
>> >>> > Also, let's use the same fonts to ensure there's no difference
>> >>> > caused
>> >>> > by font selection.
>> >>> >
>> >>> > It should help reduce the memory allocation noise that's not
>> >>> > relevant
>> >>> > to this problem (probably).
>> >>> >
>> >>> >> Fwiw: your benchmark with p=0.782 means according to ...
>> >>> >
>> >>> > Yes, I'm aware, I was running off of battery power, hence there
>> >>> > might
>> >>> > have been weirdness...
>> >>> > the individual results were also flipping between two values, which
>> >>> > can suggest either some caching
>> >>> > difference or allocation difference.... either way,
>> >>> >
>> >>> >> I tried to run that benchmark as well, but you probably removed
>> >>> >> it.
>> >>> >
>> >>> > I didn't really upload it in the first place :)
>> >>> >
>> >>> > + Egon
>> >>> >
>> >>> > On Sun, Oct 22, 2023 at 5:23 PM <fgergo@gmail.com> wrote:
>> >>> >>
>> >>> >> Thanks for the detailed benchmarking instructions, this helps a
>> >>> >> lot!
>> >>> >> Please reply if I missed something.
>> >>> >> I still see very different numbers.
>> >>> >> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
>> >>> >>
>> >>> >> Fwiw: your benchmark with p=0.782 means according to
>> >>> >> https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
>> >>> >> "it's very likely the differences for this benchmark are simply
>> >>> >> due
>> >>> >> to
>> >>> >> random chance"
>> >>> >> I tried to run that benchmark as well, but you probably removed
>> >>> >> it.
>> >>> >> (If I should run that as well, please share.)
>> >>> >>
>> >>> >> Thanks a lot for your work!
>> >>> >>
>> >>> >> cheers,
>> >>> >> Gergo
>> >>> >>
>> >>> >> $ cat cmd_test.go
>> >>> >> package benchGiochange
>> >>> >>
>> >>> >> import (
>> >>> >>         "testing"
>> >>> >>
>> >>> >>         "gioui.org/font/gofont"
>> >>> >>         "gioui.org/io/system"
>> >>> >>         "gioui.org/layout"
>> >>> >>         "gioui.org/op"
>> >>> >>         "gioui.org/widget/material"
>> >>> >> )
>> >>> >>
>> >>> >> 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)
>> >>> >>         }
>> >>> >> }
>> >>> >> $ ./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
>> >>> >> $ ./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
>> >>> >> $ go test -bench . -count 10 | tee babe7a2.log
>> >>> >> goos: linux
>> >>> >> goarch: amd64
>> >>> >> pkg: benchGiochange
>> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >>> >> BenchmarkLayout-2         102739             11058 ns/op
>> >>> >> BenchmarkLayout-2         103851             10853 ns/op
>> >>> >> BenchmarkLayout-2         155602             11012 ns/op
>> >>> >> BenchmarkLayout-2         136452             11813 ns/op
>> >>> >> BenchmarkLayout-2         133518             12070 ns/op
>> >>> >> BenchmarkLayout-2         159237             11828 ns/op
>> >>> >> BenchmarkLayout-2         121366             10532 ns/op
>> >>> >> BenchmarkLayout-2         109147             11122 ns/op
>> >>> >> BenchmarkLayout-2         143758             12059 ns/op
>> >>> >> BenchmarkLayout-2         147904             11676 ns/op
>> >>> >> PASS
>> >>> >> ok      benchGiochange  16.255s
>> >>> >> $ go test -bench . -benchtime 30s -cpuprofile babe7a2.cpu.pprof
>> >>> >> goos: linux
>> >>> >> goarch: amd64
>> >>> >> pkg: benchGiochange
>> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >>> >> BenchmarkLayout-2        3206446             11869 ns/op
>> >>> >> PASS
>> >>> >> ok      benchGiochange  49.782s
>> >>> >> $ ./changeToCommit.sh 43c47f0
>> >>> >> 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.20230719080151-43c47f08835c
>> >>> >>
>> >>> >> # Edit cmd_test.go
>> >>> >>
>> >>> >> $ go test -bench . -count 10 | tee 43c47f0.log
>> >>> >> goos: linux
>> >>> >> goarch: amd64
>> >>> >> pkg: benchGiochange
>> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >>> >> BenchmarkLayout-2          89000             13615 ns/op
>> >>> >> BenchmarkLayout-2          95593             14283 ns/op
>> >>> >> BenchmarkLayout-2          96690             15635 ns/op
>> >>> >> BenchmarkLayout-2          98223             15432 ns/op
>> >>> >> BenchmarkLayout-2         103114             16133 ns/op
>> >>> >> BenchmarkLayout-2         130970             17090 ns/op
>> >>> >> BenchmarkLayout-2         118478             16265 ns/op
>> >>> >> BenchmarkLayout-2          99070             15630 ns/op
>> >>> >> BenchmarkLayout-2         105874             17093 ns/op
>> >>> >> BenchmarkLayout-2         122764             16051 ns/op
>> >>> >> PASS
>> >>> >> ok      benchGiochange  18.116s
>> >>> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof
>> >>> >> goos: linux
>> >>> >> goarch: amd64
>> >>> >> pkg: benchGiochange
>> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >>> >> BenchmarkLayout-2        2449099             13154 ns/op
>> >>> >> PASS
>> >>> >> ok      benchGiochange  47.426s
>> >>> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof.2
>> >>> >> goos: linux
>> >>> >> goarch: amd64
>> >>> >> pkg: benchGiochange
>> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >>> >> BenchmarkLayout-2        2911257             13267 ns/op
>> >>> >> PASS
>> >>> >> ok      benchGiochange  51.423s
>> >>> >> $ benchstat babe7a2.log 43c47f0.log |tee benchstat.result.txt
>> >>> >> goos: linux
>> >>> >> goarch: amd64
>> >>> >> pkg: benchGiochange
>> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >>> >>          │ babe7a2.log │             43c47f0.log              │
>> >>> >>          │   sec/op    │    sec/op     vs base                │
>> >>> >> Layout-2   11.40µ ± 6%   15.84µ ± 10%  +38.99% (p=0.000 n=10)
>> >>> >>
>> >>> >>
>> >>> >>
>> >>> >> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
>> >>> >> > 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
>> >>> >> >> >>>
>> >>> >> >> >>
>> >>> >> >> >
>> >>> >> >
>> >>> >
>> >>
>> >
>

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

Details
Message ID
<CANtNKfobU6rMcKm=R4_vfamPD79C1qyb_vLoXBzoXvit5UGZgw@mail.gmail.com>
In-Reply-To
<CA+ctqrpKxS8TY6FOq=YXorEvuscVk6UFCr6+XEBZC=BMHKgqwg@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
The changes have been merged to main.

PS: main requires some changes to your code.

On Tue, Oct 24, 2023 at 5:47 PM <fgergo@gmail.com> wrote:
>
> Thanks for the patches! I'll rerun all tests as soon as they are merged.
>
> fwiw: I ran the benchmarks with the same fonts with bigger n on 2
> android phones (>100% and ~40%)
> termux, go1.21.3 and again on the old linux machine (~12%) and with
> different fonts on linux (~20%)
>
> The linux benchmarks show that on linux 7% of slowdown I experienced
> came from using a default(?) font. Is this expected? Is there a way
> without measuring the layout time to guesstimate a "fast" font?
>
> For benchmarking I used a fairly self-contained set of scripts on
> the google drive share (bench.tar).
> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
>
> $ tar xf bench.tar; cd bench
> $ ./rundiff.sh # using the same fonts; benchmark comparison results in
> benchstat*.txt files
>
> android phone1:
> # same fonts
> $ cat benchstat.*|grep Layout
> Layout-6                 522.5µ ± 0%   1140.1µ ± 3%  +118.18% (p=0.000 n=30)
> Layout-6                 521.9µ ± 0%   1117.4µ ± 4%  +114.08% (p=0.000 n=30
>
> android phone2:
> # same fonts
> $ cat benchstat.*|grep Layout
> Layout-8                 184.6µ ± 0%   260.9µ ± 0%  +41.31% (p=0.000 n=100)
> Layout-8                 187.8µ ± 0%   262.0µ ± 0%  +39.49% (p=0.000 n=100)
>
> The oldandsilent amd64+Linux+X machine:
> # same fonts
> $ cat benchstat.*|grep Layout
> Layout-2                 165.5µ ± 1%   187.6µ ± 1%  +13.36% (p=0.000 n=100)
> Layout-2                 167.6µ ± 1%   188.0µ ± 1%  +12.16% (p=0.000 n=100)
> Layout-2                 167.7µ ± 1%   188.2µ ± 1%  +12.22% (p=0.000 n=100)
>
> # with different fonts:
> $ cat benchstat.*|grep Layout
> Layout-2                 169.4µ ± 3%   207.0µ ± 1%  +22.18% (p=0.000 n=42)
> Layout-2                 174.8µ ± 3%   209.6µ ± 2%  +19.88% (p=0.000 n=42)
> Layout-2                 172.3µ ± 2%   209.6µ ± 1%  +21.65% (p=0.000 n=42)
>
> On 10/24/23, Egon Elbre <egonelbre@gmail.com> wrote:
> > So,
> >
> > I sent a few patches that should improve this.
> > https://lists.sr.ht/~eliasnaur/gio-patches/patches/45986
> >
> > They haven't been merged yet.
> >
> > I'm looking where it can be further optimized.
> >
> > + Egon
> >
> >
> > On Tue, Oct 24, 2023 at 12:07 PM <fgergo@gmail.com> wrote:
> >>
> >> Same share, under win/ the results are for windows10.
> >> benchstat reports ~3%.
> >>
> >>
> >> On 10/23/23, fgergo@gmail.com <fgergo@gmail.com> wrote:
> >> > Thanks!
> >> > Uploaded all files to same google drive share. (Previous files: arch/):
> >> > https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
> >> >
> >> >
> >> > On 10/23/23, Egon Elbre <egonelbre@gmail.com> wrote:
> >> >> Ah, sorry,
> >> >> I made a typo while writing the code directly in email editor, this
> >> >> should work now:
> >> >>
> >> >> ```
> >> >> func BenchmarkLayout(b *testing.B) {
> >> >>     // uncomment to use with commit 43c47f0
> >> >>     t := material.NewTheme()
> >> >>     t.Shaper =
> >> >> text.NewShaper(text.WithCollection(gofont.Collection()))
> >> >>     // uncomment to use with commit babe7a2
> >> >>     // t := material.NewTheme(gofont.Collection())
> >> >>     ops := &op.Ops{}
> >> >>
> >> >>     b.ResetTimer()
> >> >>     for n := 0; n < b.N; n++ {
> >> >>         gtx := layout.NewContext(ops, system.FrameEvent{})
> >> >>         for i := 0; i < 10; i++ {
> >> >>             material.Label(t, 10,
> >> >> "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
> >> >>             material.Label(t, 10, "oifajmorfj983
> >> >> 4mroaermfnkli").Layout(gtx)
> >> >>             material.Label(t, 10, "1234 1234 5434 1234
> >> >> 41234").Layout(gtx)
> >> >>         }
> >> >>     }
> >> >> }
> >> >> ```
> >> >>
> >> >> On Mon, Oct 23, 2023 at 1:54 AM <fgergo@gmail.com> wrote:
> >> >>>
> >> >>> This won't compile with 43c47f0.
> >> >>> $ ./changeToCommit.sh v0.2.0
> >> >>> go: creating new go.mod: module benchGiochange
> >> >>> go: to add module requirements and sums:
> >> >>>         go mod tidy
> >> >>> go: added gioui.org v0.2.0
> >> >>> $ go test -bench . -count 10 | tee 0.2.0.log
> >> >>> # benchGiochange [benchGiochange.test]
> >> >>> ./cmd_test.go:17:2: shaper declared and not used
> >> >>> FAIL    benchGiochange [build failed]
> >> >>>
> >> >>> Could you please point to a gioui example using shaper?
> >> >>>
> >> >>> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
> >> >>> > It does seem that the caching key used in text shaper is slower.
> >> >>> > Also, can you rerun these things with this benchmark:
> >> >>> > ```
> >> >>> > func BenchmarkLayout(b *testing.B) {
> >> >>> >     // uncomment to use with commit 43c47f0
> >> >>> >     t := material.NewTheme()
> >> >>> >     shaper :=
> >> >>> > text.NewShaper(text.WithCollection(gofont.Collection()))
> >> >>> >     // uncomment to use with commit babe7a2
> >> >>> >     // t := material.NewTheme(gofont.Collection())
> >> >>> >     ops := &op.Ops{}
> >> >>> >
> >> >>> >     b.ResetTimer()
> >> >>> >     for n := 0; n < b.N; n++ {
> >> >>> >         gtx := layout.NewContext(ops, system.FrameEvent{})
> >> >>> >         for i := 0; i < 3; i++ {
> >> >>> >             material.Label(t, 10,
> >> >>> > "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
> >> >>> >             material.Label(t, 10, "1234 1234 5434 1234
> >> >>> > 41234").Layout(gtx)
> >> >>> >         }
> >> >>> >     }
> >> >>> > }
> >> >>> > ```
> >> >>> >
> >> >>> > While looking at the profile results I realized that it was still
> >> >>> > subtly
> >> >>> > wrong.
> >> >>> > I.e. it was creating a huge single frame which contains tons of
> >> >>> > text
> >> >>> > instead of rendering multiple frames
> >> >>> > each with less text.
> >> >>> >
> >> >>> > Also, let's use the same fonts to ensure there's no difference
> >> >>> > caused
> >> >>> > by font selection.
> >> >>> >
> >> >>> > It should help reduce the memory allocation noise that's not
> >> >>> > relevant
> >> >>> > to this problem (probably).
> >> >>> >
> >> >>> >> Fwiw: your benchmark with p=0.782 means according to ...
> >> >>> >
> >> >>> > Yes, I'm aware, I was running off of battery power, hence there
> >> >>> > might
> >> >>> > have been weirdness...
> >> >>> > the individual results were also flipping between two values, which
> >> >>> > can suggest either some caching
> >> >>> > difference or allocation difference.... either way,
> >> >>> >
> >> >>> >> I tried to run that benchmark as well, but you probably removed
> >> >>> >> it.
> >> >>> >
> >> >>> > I didn't really upload it in the first place :)
> >> >>> >
> >> >>> > + Egon
> >> >>> >
> >> >>> > On Sun, Oct 22, 2023 at 5:23 PM <fgergo@gmail.com> wrote:
> >> >>> >>
> >> >>> >> Thanks for the detailed benchmarking instructions, this helps a
> >> >>> >> lot!
> >> >>> >> Please reply if I missed something.
> >> >>> >> I still see very different numbers.
> >> >>> >> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
> >> >>> >>
> >> >>> >> Fwiw: your benchmark with p=0.782 means according to
> >> >>> >> https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
> >> >>> >> "it's very likely the differences for this benchmark are simply
> >> >>> >> due
> >> >>> >> to
> >> >>> >> random chance"
> >> >>> >> I tried to run that benchmark as well, but you probably removed
> >> >>> >> it.
> >> >>> >> (If I should run that as well, please share.)
> >> >>> >>
> >> >>> >> Thanks a lot for your work!
> >> >>> >>
> >> >>> >> cheers,
> >> >>> >> Gergo
> >> >>> >>
> >> >>> >> $ cat cmd_test.go
> >> >>> >> package benchGiochange
> >> >>> >>
> >> >>> >> import (
> >> >>> >>         "testing"
> >> >>> >>
> >> >>> >>         "gioui.org/font/gofont"
> >> >>> >>         "gioui.org/io/system"
> >> >>> >>         "gioui.org/layout"
> >> >>> >>         "gioui.org/op"
> >> >>> >>         "gioui.org/widget/material"
> >> >>> >> )
> >> >>> >>
> >> >>> >> 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)
> >> >>> >>         }
> >> >>> >> }
> >> >>> >> $ ./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
> >> >>> >> $ ./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
> >> >>> >> $ go test -bench . -count 10 | tee babe7a2.log
> >> >>> >> goos: linux
> >> >>> >> goarch: amd64
> >> >>> >> pkg: benchGiochange
> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >> >>> >> BenchmarkLayout-2         102739             11058 ns/op
> >> >>> >> BenchmarkLayout-2         103851             10853 ns/op
> >> >>> >> BenchmarkLayout-2         155602             11012 ns/op
> >> >>> >> BenchmarkLayout-2         136452             11813 ns/op
> >> >>> >> BenchmarkLayout-2         133518             12070 ns/op
> >> >>> >> BenchmarkLayout-2         159237             11828 ns/op
> >> >>> >> BenchmarkLayout-2         121366             10532 ns/op
> >> >>> >> BenchmarkLayout-2         109147             11122 ns/op
> >> >>> >> BenchmarkLayout-2         143758             12059 ns/op
> >> >>> >> BenchmarkLayout-2         147904             11676 ns/op
> >> >>> >> PASS
> >> >>> >> ok      benchGiochange  16.255s
> >> >>> >> $ go test -bench . -benchtime 30s -cpuprofile babe7a2.cpu.pprof
> >> >>> >> goos: linux
> >> >>> >> goarch: amd64
> >> >>> >> pkg: benchGiochange
> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >> >>> >> BenchmarkLayout-2        3206446             11869 ns/op
> >> >>> >> PASS
> >> >>> >> ok      benchGiochange  49.782s
> >> >>> >> $ ./changeToCommit.sh 43c47f0
> >> >>> >> 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.20230719080151-43c47f08835c
> >> >>> >>
> >> >>> >> # Edit cmd_test.go
> >> >>> >>
> >> >>> >> $ go test -bench . -count 10 | tee 43c47f0.log
> >> >>> >> goos: linux
> >> >>> >> goarch: amd64
> >> >>> >> pkg: benchGiochange
> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >> >>> >> BenchmarkLayout-2          89000             13615 ns/op
> >> >>> >> BenchmarkLayout-2          95593             14283 ns/op
> >> >>> >> BenchmarkLayout-2          96690             15635 ns/op
> >> >>> >> BenchmarkLayout-2          98223             15432 ns/op
> >> >>> >> BenchmarkLayout-2         103114             16133 ns/op
> >> >>> >> BenchmarkLayout-2         130970             17090 ns/op
> >> >>> >> BenchmarkLayout-2         118478             16265 ns/op
> >> >>> >> BenchmarkLayout-2          99070             15630 ns/op
> >> >>> >> BenchmarkLayout-2         105874             17093 ns/op
> >> >>> >> BenchmarkLayout-2         122764             16051 ns/op
> >> >>> >> PASS
> >> >>> >> ok      benchGiochange  18.116s
> >> >>> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof
> >> >>> >> goos: linux
> >> >>> >> goarch: amd64
> >> >>> >> pkg: benchGiochange
> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >> >>> >> BenchmarkLayout-2        2449099             13154 ns/op
> >> >>> >> PASS
> >> >>> >> ok      benchGiochange  47.426s
> >> >>> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof.2
> >> >>> >> goos: linux
> >> >>> >> goarch: amd64
> >> >>> >> pkg: benchGiochange
> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >> >>> >> BenchmarkLayout-2        2911257             13267 ns/op
> >> >>> >> PASS
> >> >>> >> ok      benchGiochange  51.423s
> >> >>> >> $ benchstat babe7a2.log 43c47f0.log |tee benchstat.result.txt
> >> >>> >> goos: linux
> >> >>> >> goarch: amd64
> >> >>> >> pkg: benchGiochange
> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
> >> >>> >>          │ babe7a2.log │             43c47f0.log              │
> >> >>> >>          │   sec/op    │    sec/op     vs base                │
> >> >>> >> Layout-2   11.40µ ± 6%   15.84µ ± 10%  +38.99% (p=0.000 n=10)
> >> >>> >>
> >> >>> >>
> >> >>> >>
> >> >>> >> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
> >> >>> >> > 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
> >> >>> >> >> >>>
> >> >>> >> >> >>
> >> >>> >> >> >
> >> >>> >> >
> >> >>> >
> >> >>
> >> >
> >

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

Details
Message ID
<CA+ctqrr8-eHs8g8roY00JkuHg-G_MWG4tj8+AD5faa3_hrtOsg@mail.gmail.com>
In-Reply-To
<CANtNKfobU6rMcKm=R4_vfamPD79C1qyb_vLoXBzoXvit5UGZgw@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
Thanks to everybody!

Sorry I haven't been following closely and I did not realize the
changes had been merged for 24 days now.

babe7a2: last commit before the shaper changes
43c47f0: new shaper
48bd5952: latest optimizations

The benchmark numbers are just great!

% cat benchstat.231117.babe7a2.48bd5952.txt
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
         │ 231117.babe7a2.log │  231117.48bd5952.log  │
         │          sec/op           │   sec/op     vs base         │
Layout-2                 164.3µ ± 2%   140.9µ ± 2%  -14.23% (n=100)
% benchstat 231117.094624.43c47f0.log 231117.094624.48bd5952.log
goos: linux
goarch: amd64
pkg: benchGiochange
cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
         │ 231117.43c47f0.log │  231117.48bd5952.log  │
         │          sec/op           │   sec/op     vs base         │
Layout-2                 186.2µ ± 2%   140.9µ ± 2%  -24.33% (n=100)

Have a nice weekend all!

cheers,
fgergo


On 11/15/23, Egon Elbre <egonelbre@gmail.com> wrote:
> The changes have been merged to main.
>
> PS: main requires some changes to your code.
>
> On Tue, Oct 24, 2023 at 5:47 PM <fgergo@gmail.com> wrote:
>>
>> Thanks for the patches! I'll rerun all tests as soon as they are merged.
>>
>> fwiw: I ran the benchmarks with the same fonts with bigger n on 2
>> android phones (>100% and ~40%)
>> termux, go1.21.3 and again on the old linux machine (~12%) and with
>> different fonts on linux (~20%)
>>
>> The linux benchmarks show that on linux 7% of slowdown I experienced
>> came from using a default(?) font. Is this expected? Is there a way
>> without measuring the layout time to guesstimate a "fast" font?
>>
>> For benchmarking I used a fairly self-contained set of scripts on
>> the google drive share (bench.tar).
>> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
>>
>> $ tar xf bench.tar; cd bench
>> $ ./rundiff.sh # using the same fonts; benchmark comparison results in
>> benchstat*.txt files
>>
>> android phone1:
>> # same fonts
>> $ cat benchstat.*|grep Layout
>> Layout-6                 522.5µ ± 0%   1140.1µ ± 3%  +118.18% (p=0.000
>> n=30)
>> Layout-6                 521.9µ ± 0%   1117.4µ ± 4%  +114.08% (p=0.000
>> n=30
>>
>> android phone2:
>> # same fonts
>> $ cat benchstat.*|grep Layout
>> Layout-8                 184.6µ ± 0%   260.9µ ± 0%  +41.31% (p=0.000
>> n=100)
>> Layout-8                 187.8µ ± 0%   262.0µ ± 0%  +39.49% (p=0.000
>> n=100)
>>
>> The oldandsilent amd64+Linux+X machine:
>> # same fonts
>> $ cat benchstat.*|grep Layout
>> Layout-2                 165.5µ ± 1%   187.6µ ± 1%  +13.36% (p=0.000
>> n=100)
>> Layout-2                 167.6µ ± 1%   188.0µ ± 1%  +12.16% (p=0.000
>> n=100)
>> Layout-2                 167.7µ ± 1%   188.2µ ± 1%  +12.22% (p=0.000
>> n=100)
>>
>> # with different fonts:
>> $ cat benchstat.*|grep Layout
>> Layout-2                 169.4µ ± 3%   207.0µ ± 1%  +22.18% (p=0.000
>> n=42)
>> Layout-2                 174.8µ ± 3%   209.6µ ± 2%  +19.88% (p=0.000
>> n=42)
>> Layout-2                 172.3µ ± 2%   209.6µ ± 1%  +21.65% (p=0.000
>> n=42)
>>
>> On 10/24/23, Egon Elbre <egonelbre@gmail.com> wrote:
>> > So,
>> >
>> > I sent a few patches that should improve this.
>> > https://lists.sr.ht/~eliasnaur/gio-patches/patches/45986
>> >
>> > They haven't been merged yet.
>> >
>> > I'm looking where it can be further optimized.
>> >
>> > + Egon
>> >
>> >
>> > On Tue, Oct 24, 2023 at 12:07 PM <fgergo@gmail.com> wrote:
>> >>
>> >> Same share, under win/ the results are for windows10.
>> >> benchstat reports ~3%.
>> >>
>> >>
>> >> On 10/23/23, fgergo@gmail.com <fgergo@gmail.com> wrote:
>> >> > Thanks!
>> >> > Uploaded all files to same google drive share. (Previous files:
>> >> > arch/):
>> >> > https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
>> >> >
>> >> >
>> >> > On 10/23/23, Egon Elbre <egonelbre@gmail.com> wrote:
>> >> >> Ah, sorry,
>> >> >> I made a typo while writing the code directly in email editor, this
>> >> >> should work now:
>> >> >>
>> >> >> ```
>> >> >> func BenchmarkLayout(b *testing.B) {
>> >> >>     // uncomment to use with commit 43c47f0
>> >> >>     t := material.NewTheme()
>> >> >>     t.Shaper =
>> >> >> text.NewShaper(text.WithCollection(gofont.Collection()))
>> >> >>     // uncomment to use with commit babe7a2
>> >> >>     // t := material.NewTheme(gofont.Collection())
>> >> >>     ops := &op.Ops{}
>> >> >>
>> >> >>     b.ResetTimer()
>> >> >>     for n := 0; n < b.N; n++ {
>> >> >>         gtx := layout.NewContext(ops, system.FrameEvent{})
>> >> >>         for i := 0; i < 10; i++ {
>> >> >>             material.Label(t, 10,
>> >> >> "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
>> >> >>             material.Label(t, 10, "oifajmorfj983
>> >> >> 4mroaermfnkli").Layout(gtx)
>> >> >>             material.Label(t, 10, "1234 1234 5434 1234
>> >> >> 41234").Layout(gtx)
>> >> >>         }
>> >> >>     }
>> >> >> }
>> >> >> ```
>> >> >>
>> >> >> On Mon, Oct 23, 2023 at 1:54 AM <fgergo@gmail.com> wrote:
>> >> >>>
>> >> >>> This won't compile with 43c47f0.
>> >> >>> $ ./changeToCommit.sh v0.2.0
>> >> >>> go: creating new go.mod: module benchGiochange
>> >> >>> go: to add module requirements and sums:
>> >> >>>         go mod tidy
>> >> >>> go: added gioui.org v0.2.0
>> >> >>> $ go test -bench . -count 10 | tee 0.2.0.log
>> >> >>> # benchGiochange [benchGiochange.test]
>> >> >>> ./cmd_test.go:17:2: shaper declared and not used
>> >> >>> FAIL    benchGiochange [build failed]
>> >> >>>
>> >> >>> Could you please point to a gioui example using shaper?
>> >> >>>
>> >> >>> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
>> >> >>> > It does seem that the caching key used in text shaper is slower.
>> >> >>> > Also, can you rerun these things with this benchmark:
>> >> >>> > ```
>> >> >>> > func BenchmarkLayout(b *testing.B) {
>> >> >>> >     // uncomment to use with commit 43c47f0
>> >> >>> >     t := material.NewTheme()
>> >> >>> >     shaper :=
>> >> >>> > text.NewShaper(text.WithCollection(gofont.Collection()))
>> >> >>> >     // uncomment to use with commit babe7a2
>> >> >>> >     // t := material.NewTheme(gofont.Collection())
>> >> >>> >     ops := &op.Ops{}
>> >> >>> >
>> >> >>> >     b.ResetTimer()
>> >> >>> >     for n := 0; n < b.N; n++ {
>> >> >>> >         gtx := layout.NewContext(ops, system.FrameEvent{})
>> >> >>> >         for i := 0; i < 3; i++ {
>> >> >>> >             material.Label(t, 10,
>> >> >>> > "abcdefghijklmnopqrstuvwxyz").Layout(gtx)
>> >> >>> >             material.Label(t, 10, "1234 1234 5434 1234
>> >> >>> > 41234").Layout(gtx)
>> >> >>> >         }
>> >> >>> >     }
>> >> >>> > }
>> >> >>> > ```
>> >> >>> >
>> >> >>> > While looking at the profile results I realized that it was
>> >> >>> > still
>> >> >>> > subtly
>> >> >>> > wrong.
>> >> >>> > I.e. it was creating a huge single frame which contains tons of
>> >> >>> > text
>> >> >>> > instead of rendering multiple frames
>> >> >>> > each with less text.
>> >> >>> >
>> >> >>> > Also, let's use the same fonts to ensure there's no difference
>> >> >>> > caused
>> >> >>> > by font selection.
>> >> >>> >
>> >> >>> > It should help reduce the memory allocation noise that's not
>> >> >>> > relevant
>> >> >>> > to this problem (probably).
>> >> >>> >
>> >> >>> >> Fwiw: your benchmark with p=0.782 means according to ...
>> >> >>> >
>> >> >>> > Yes, I'm aware, I was running off of battery power, hence there
>> >> >>> > might
>> >> >>> > have been weirdness...
>> >> >>> > the individual results were also flipping between two values,
>> >> >>> > which
>> >> >>> > can suggest either some caching
>> >> >>> > difference or allocation difference.... either way,
>> >> >>> >
>> >> >>> >> I tried to run that benchmark as well, but you probably removed
>> >> >>> >> it.
>> >> >>> >
>> >> >>> > I didn't really upload it in the first place :)
>> >> >>> >
>> >> >>> > + Egon
>> >> >>> >
>> >> >>> > On Sun, Oct 22, 2023 at 5:23 PM <fgergo@gmail.com> wrote:
>> >> >>> >>
>> >> >>> >> Thanks for the detailed benchmarking instructions, this helps a
>> >> >>> >> lot!
>> >> >>> >> Please reply if I missed something.
>> >> >>> >> I still see very different numbers.
>> >> >>> >> https://drive.google.com/drive/folders/1xrYVKIS1hqQ8yXBYorj_uGhM8pemDXC3
>> >> >>> >>
>> >> >>> >> Fwiw: your benchmark with p=0.782 means according to
>> >> >>> >> https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
>> >> >>> >> "it's very likely the differences for this benchmark are simply
>> >> >>> >> due
>> >> >>> >> to
>> >> >>> >> random chance"
>> >> >>> >> I tried to run that benchmark as well, but you probably removed
>> >> >>> >> it.
>> >> >>> >> (If I should run that as well, please share.)
>> >> >>> >>
>> >> >>> >> Thanks a lot for your work!
>> >> >>> >>
>> >> >>> >> cheers,
>> >> >>> >> Gergo
>> >> >>> >>
>> >> >>> >> $ cat cmd_test.go
>> >> >>> >> package benchGiochange
>> >> >>> >>
>> >> >>> >> import (
>> >> >>> >>         "testing"
>> >> >>> >>
>> >> >>> >>         "gioui.org/font/gofont"
>> >> >>> >>         "gioui.org/io/system"
>> >> >>> >>         "gioui.org/layout"
>> >> >>> >>         "gioui.org/op"
>> >> >>> >>         "gioui.org/widget/material"
>> >> >>> >> )
>> >> >>> >>
>> >> >>> >> 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)
>> >> >>> >>         }
>> >> >>> >> }
>> >> >>> >> $ ./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
>> >> >>> >> $ ./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
>> >> >>> >> $ go test -bench . -count 10 | tee babe7a2.log
>> >> >>> >> goos: linux
>> >> >>> >> goarch: amd64
>> >> >>> >> pkg: benchGiochange
>> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >> >>> >> BenchmarkLayout-2         102739             11058 ns/op
>> >> >>> >> BenchmarkLayout-2         103851             10853 ns/op
>> >> >>> >> BenchmarkLayout-2         155602             11012 ns/op
>> >> >>> >> BenchmarkLayout-2         136452             11813 ns/op
>> >> >>> >> BenchmarkLayout-2         133518             12070 ns/op
>> >> >>> >> BenchmarkLayout-2         159237             11828 ns/op
>> >> >>> >> BenchmarkLayout-2         121366             10532 ns/op
>> >> >>> >> BenchmarkLayout-2         109147             11122 ns/op
>> >> >>> >> BenchmarkLayout-2         143758             12059 ns/op
>> >> >>> >> BenchmarkLayout-2         147904             11676 ns/op
>> >> >>> >> PASS
>> >> >>> >> ok      benchGiochange  16.255s
>> >> >>> >> $ go test -bench . -benchtime 30s -cpuprofile babe7a2.cpu.pprof
>> >> >>> >> goos: linux
>> >> >>> >> goarch: amd64
>> >> >>> >> pkg: benchGiochange
>> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >> >>> >> BenchmarkLayout-2        3206446             11869 ns/op
>> >> >>> >> PASS
>> >> >>> >> ok      benchGiochange  49.782s
>> >> >>> >> $ ./changeToCommit.sh 43c47f0
>> >> >>> >> 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.20230719080151-43c47f08835c
>> >> >>> >>
>> >> >>> >> # Edit cmd_test.go
>> >> >>> >>
>> >> >>> >> $ go test -bench . -count 10 | tee 43c47f0.log
>> >> >>> >> goos: linux
>> >> >>> >> goarch: amd64
>> >> >>> >> pkg: benchGiochange
>> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >> >>> >> BenchmarkLayout-2          89000             13615 ns/op
>> >> >>> >> BenchmarkLayout-2          95593             14283 ns/op
>> >> >>> >> BenchmarkLayout-2          96690             15635 ns/op
>> >> >>> >> BenchmarkLayout-2          98223             15432 ns/op
>> >> >>> >> BenchmarkLayout-2         103114             16133 ns/op
>> >> >>> >> BenchmarkLayout-2         130970             17090 ns/op
>> >> >>> >> BenchmarkLayout-2         118478             16265 ns/op
>> >> >>> >> BenchmarkLayout-2          99070             15630 ns/op
>> >> >>> >> BenchmarkLayout-2         105874             17093 ns/op
>> >> >>> >> BenchmarkLayout-2         122764             16051 ns/op
>> >> >>> >> PASS
>> >> >>> >> ok      benchGiochange  18.116s
>> >> >>> >> $ go test -bench . -benchtime 30s -cpuprofile 43c47f0.cpu.pprof
>> >> >>> >> goos: linux
>> >> >>> >> goarch: amd64
>> >> >>> >> pkg: benchGiochange
>> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >> >>> >> BenchmarkLayout-2        2449099             13154 ns/op
>> >> >>> >> PASS
>> >> >>> >> ok      benchGiochange  47.426s
>> >> >>> >> $ go test -bench . -benchtime 30s -cpuprofile
>> >> >>> >> 43c47f0.cpu.pprof.2
>> >> >>> >> goos: linux
>> >> >>> >> goarch: amd64
>> >> >>> >> pkg: benchGiochange
>> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >> >>> >> BenchmarkLayout-2        2911257             13267 ns/op
>> >> >>> >> PASS
>> >> >>> >> ok      benchGiochange  51.423s
>> >> >>> >> $ benchstat babe7a2.log 43c47f0.log |tee benchstat.result.txt
>> >> >>> >> goos: linux
>> >> >>> >> goarch: amd64
>> >> >>> >> pkg: benchGiochange
>> >> >>> >> cpu: AMD GX-217GA SOC with Radeon(tm) HD Graphics
>> >> >>> >>          │ babe7a2.log │             43c47f0.log              │
>> >> >>> >>          │   sec/op    │    sec/op     vs base                │
>> >> >>> >> Layout-2   11.40µ ± 6%   15.84µ ± 10%  +38.99% (p=0.000 n=10)
>> >> >>> >>
>> >> >>> >>
>> >> >>> >>
>> >> >>> >> On 10/22/23, Egon Elbre <egonelbre@gmail.com> wrote:
>> >> >>> >> > 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
>> >> >>> >> >> >>>
>> >> >>> >> >> >>
>> >> >>> >> >> >
>> >> >>> >> >
>> >> >>> >
>> >> >>
>> >> >
>> >
>

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

Details
Message ID
<CAFcc3FR4uZOKi4C=y14qdU0m9d6AQFPRTXb81g_Q2+-LWLnw7g@mail.gmail.com>
In-Reply-To
<CA+ctqrr8-eHs8g8roY00JkuHg-G_MWG4tj8+AD5faa3_hrtOsg@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
On Fri, Nov 17, 2023 at 11:08 AM <fgergo@gmail.com> wrote:
>
> Thanks to everybody!
>
> Sorry I haven't been following closely and I did not realize the
> changes had been merged for 24 days now.

They haven't been, so don't feel too bad. I think you're looking at
the timestamp of when Egon wrote the commit, which is not the same as
the timestamp at which I merged it into core. It was only merged
shortly before Egon sent the email.

Cheers,
Chris
Reply to thread Export thread (mbox)