treeform / fidget

Figma based UI library for nim, with HTML and OpenGL backends.
MIT License
768 stars 33 forks source link

[Add font recycling especially for CJK] Possible memory leak (related to fonts?) #93

Open ghost opened 4 years ago

ghost commented 4 years ago

When trying padofcode/padoftext examples I noticed that when you paste a lot of text, and then remove it, the memory usage will forever stay much higher.

Steps: Run padofcode/padoftext Paste a big amount of text (RAM usage goes higher) Remove all text -> RAM usage is still the same

ghost commented 4 years ago

With dumpNumberOfInstances I get:

[Heap] seq[GlyphPosition]: #3; bytes: 10833856
[Heap] string: #107367; bytes: 4692843
[Heap] seq[Rune]: #1; bytes: 262176
[Heap] seq[float32]: #1035; bytes: 110712
[Heap] Glyph: #911; bytes: 94744
[Heap] seq[Segment]: #52; bytes: 61968
[Heap] KeyValuePairSeq[system.int, system.int]: #1; bytes: 49184
[Heap] KeyValuePairSeq[system.string, font.Glyph]: #1; bytes: 49184
[Heap] seq[PathCommand]: #37; bytes: 18544
[Heap] seq[uint8]: #1; bytes: 16416
[Heap] seq[float64]: #2; bytes: 16064
[Heap] seq[uint16]: #2; bytes: 14400
[Heap] KeyValuePairSeq[hashes.Hash, vmath.Rect]: #1; bytes: 8224
[Heap] seq[int]: #1; bytes: 8224
[Heap] seq[Glyph]: #1; bytes: 7320
[Heap] KeyValuePairSeq[hashes.Hash, vmath.Vec2]: #1; bytes: 6176
[Heap] KeyValuePairSeq[system.string, system.string]: #1; bytes: 6176
[Heap] seq[LongHorMetricRecrod]: #1; bytes: 4128
[Heap] KeyValuePairSeq[system.string, perf.CountSize]: #1; bytes: 4128
[Heap] seq[uint32]: #1; bytes: 4128
[Heap] KeyValuePairSeq[system.string, types.Chunk]: #1; bytes: 2592
[Heap] seq[seq[Segment]]: #37; bytes: 2368
[Heap] seq[NameRecord]: #1; bytes: 1568
[Heap] KeyValuePairSeq[system.string, font.Font]: #1; bytes: 1568
[Heap] seq[bool]: #4; bytes: 1520
[Heap] Node: #3; bytes: 1056
[Heap] seq[Uniform]: #2; bytes: 768
[Heap] Context: #1; bytes: 448
[Heap] seq[Mat4]: #1; bytes: 288
[Heap] seq[Node]: #5; bytes: 216
[Heap] seq[ShaderAttrib]: #2; bytes: 192
[Heap] TextBox: #1; bytes: 144
[Heap] Font: #1; bytes: 144
[Heap] OtfFont: #1; bytes: 136
[Heap] OS2Table: #1; bytes: 128
[Heap] StringStream: #1; bytes: 120
[Heap] seq[Texture]: #1; bytes: 104
[Heap] seq[string]: #2; bytes: 96
[Heap] Shader: #2; bytes: 96
[Heap] Keyboard: #1; bytes: 88
[Heap] HeadTable: #1; bytes: 80
[Heap] seq[EncodingRecord]: #1; bytes: 64
[Heap] TimeSeries: #2; bytes: 64
[Heap] MaxpTable: #1; bytes: 56
[Heap] Mouse: #1; bytes: 52
[Heap] CmapTable: #1; bytes: 48
[Heap] HheaTable: #1; bytes: 44
[Heap] HmtxTable: #1; bytes: 32
[Heap] NameTable: #1; bytes: 32
[Heap] TableRef[system.string, perf.CountSize]: #1; bytes: 32
[Heap] TableRef[system.string, system.string]: #1; bytes: 32
[Heap] LocaTable: #1; bytes: 24
[Heap] GlyfTable: #1; bytes: 24
[Heap] total number of bytes: 16282819
[Heap] allocs/deallocs: 193737964/193627474
ghost commented 4 years ago

Tested with refc/refc+useMalloc/orc/orc+useMalloc on latest devel, all show the same behaviour. Not sure if this is a Nim regression or fidget (or typography) bug

treeform commented 3 years ago

I don't clean up letter after they are rasterized even if you remove it from text. This is usually not a problem for alphabet based languages but could be an issue for CJK. I don't have a good solution for this yet.