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.
Go version
go version 1.22
Output of
go env
in your module/workspace:What did you do?
In go-text/typesetting, we use
bidi
to segment the input text. We store and reuse onebidi.Paragraph
object, calling itsSetString
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 newrun []int
slice, but it is perhaps harder to get rid of this allocation.