golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
120.1k stars 17.24k forks source link

x/text/unicode/bidi: consider reusing internal slices #67098

Open benoitkugler opened 2 weeks ago

benoitkugler commented 2 weeks ago

Go version

go version 1.22

Output of go env in your module/workspace:

Non relevant

What did you do?

In go-text/typesetting, we use bidi to segment the input text. We store and reuse one bidi.Paragraph object, calling its SetString method for each new input.

What did you see happen?

The bidi.Paragraph.prepareInput method has high memory allocation.

What did you expect to see?

Only few allocations. If possible, the slices pairTypes, pairValues, types should reuse their capacity (instead of being freed and immediately re-allocated).

On the same topic, paragraph.determineLevelRuns allocates a new run []int slice, but it is perhaps harder to get rid of this allocation.

mauri870 commented 2 weeks ago

Friendly ping @mpvl per https://dev.golang.org/owners