From 6937a5dd1f39997ffd028546e6c75895ef0dc46f Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Wed, 5 Apr 2023 12:26:06 -0400 Subject: [PATCH] go.*,text: update go-text to pick up font transformation caching This commit picks up improvements in upstream go-text that (among other things) allow the shaper to reuse a lot of information when shaping the same font face multiple times (using an LRU cache to keep that information available). I've tried to pick a reasonable default LRU size of 32 faces. My simple benchmarks indicate a definitive performance gain and reduction in memory use across the board, which is especially noticable for complex fonts like arabic and emoji. Signed-off-by: Chris Waldon --- go.mod | 2 +- go.sum | 4 ++-- text/shaper.go | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 11bc3421..95bc680e 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 gioui.org/shader v1.0.6 - github.com/go-text/typesetting v0.0.0-20230329143336-a38d00edd832 + github.com/go-text/typesetting v0.0.0-20230405155246-bf9c697c6e16 golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 golang.org/x/image v0.5.0 diff --git a/go.sum b/go.sum index 126d100a..b5847017 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,8 @@ gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 h1:AGDDxsJE1RpcXTAxPG2B4jrwVUJG gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ= gioui.org/shader v1.0.6 h1:cvZmU+eODFR2545X+/8XucgZdTtEjR3QWW6W65b0q5Y= gioui.org/shader v1.0.6/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM= -github.com/go-text/typesetting v0.0.0-20230329143336-a38d00edd832 h1:yV4rFdcvwZXE0lZZ3EoBWjVysHyVo8DLY8VihDciNN0= -github.com/go-text/typesetting v0.0.0-20230329143336-a38d00edd832/go.mod h1:zvWM81wAVW6QfVDI6yxfbCuoLnobSYTuMsrXU/u11y8= +github.com/go-text/typesetting v0.0.0-20230405155246-bf9c697c6e16 h1:DvHeDNqK8cxdZ7C6y88pt3uE7euZH7/LluzyfnUfH/Q= +github.com/go-text/typesetting v0.0.0-20230405155246-bf9c697c6e16/go.mod h1:zvWM81wAVW6QfVDI6yxfbCuoLnobSYTuMsrXU/u11y8= github.com/go-text/typesetting-utils v0.0.0-20230326210548-458646692de6 h1:zAAA1U4ykFwqPbcj6YDxvq3F2g0wc/ngPfLJjkR/8zs= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/text/shaper.go b/text/shaper.go index 0c4a7ab3..f82973e9 100644 --- a/text/shaper.go +++ b/text/shaper.go @@ -200,6 +200,7 @@ func NewShaper(collection []FontFace) *Shaper { for _, f := range collection { l.shaper.Load(f) } + l.shaper.shaper.SetFontCacheSize(32) return l } -- 2.45.2