This is a strange bug that requires many conditions at the same time to reproduce
Reproduction: https://alansongzoom.github.io/canvaskit-memleak-repro
Take a memory heap snapshot with dev tools after js execution finishes (“Loading…” text removed). Didn’t use jsfiddle because fonts can’t be uploaded, so please copy the script to change the used font.
Mem leak:
When using SourceHanSans (file is variable font), js heap size is 2165MB
When using NotoSansCJK (file is not variable font), js heap size is 424MB
Normal:
When using Roboto (file is not variable font), js heap size is 138MB which is the initial size.
-------------------
As a side note, performance with SourceHanSans variable font using simple input of “test” is extremely slow - taking 17 seconds to for the tests - seems to all be stuck on sfnt_init_face calls.
NotoSansCJK takes ~240ms for the test while Roboto takes ~120ms.
Sorry I completely forgot to explain what I’m doing in the tests.
The test was:
The expected js heap size should be the initial size (~150MB), because we’re deleting everything (builder/paragraph) every time, and we’re using the same small text input (“test”).
The actual result is memory leak - js heap taking 400MB to 2GB depending on the font use when `fontVariation` options was passed, and it grows with number of iterations. Both variable and non-variable fonts trigger the leak, so it might be related to the font formats.
The test script is located at https://github.com/alansongzoom/canvaskit-memleak-repro/blob/main/index.html , copying here for convenience:
--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/e31530ee-74cf-4083-a533-effe9be3953cn%40googlegroups.com.
Thank you for the detailed explanation, now I finally seem to understand the problem:
As you said, FontCollection should be a singleton, so paragraph builders with FontMgr or TypefaceFontProvider should always be using the same FontCollection instance.
However, that seems not the case (multiple FontCollections being created), which lead to the unresolvedCodepoints() behavior confusion in https://groups.google.com/g/skia-discuss/c/53A-RJjNzx4: