textlayout
textlayout copied to clipboard
Trim down or minimize memory usage
We have noticed, partly based on the comment here, that the following map is massive:
https://github.com/benoitkugler/textlayout/blob/f0394e70c9d258b1564d4709a5383d7ab6461e34/fonts/glyphsnames/glyphs.go#L118 A map of, according to the comment, 2462 different strings result in a lot of memory usage and quite a huge piece of binary size increases. Can this map be reduced in any way, only created when actually needed or something like that? It might make sense to convert it into one large switch-case (especially now that Go 1.19 uses jump tables for large int and string switch cases) as the Go compiler more easily can optimize that but it would have to be tested to make sure that it isn't noticeably slower.
How urgent is this optimization ? The thing is that this map is only useful for Type1 fonts, and the long term plan for this package is to be integrated in go-text, probably without support for Type1 fonts, which will make this problem disappear (and further reduce memory usage..)
Thanks for the answer. I would personally say that it is relatively important if we want to avoid the large memory increase before publishing the v2.3.0 release. While all of it likely isn't coming from here, I am currently seeing a doubling of memory usage in my application and that isn't very nice
I've started working on a new version of the package which will remove this issue (by removing unused dependency). In the meantime, I'll gladly accept a PR implementing one of the idea you proposed.
Great. I'll try to have a look at that later in the week :)
I ran staticcheck
on the repository and it notes that as lot of stuff is unused. I will go though and clean up some unused stuff. It might be that some stuff is unused by mistake but you'll find out during the PR-review, I guess :)