FreeType allocates large amount of memory when NotoSansCJK-VF is used.
When I use a FreeType for NotoSansCJK-VF font with variation axis, hundreds of kilobytes of memories are allocated. (200-300 kb)
NotoSansCJK-VF: https://github.com/notofonts/noto-cjk/blob/main/Sans/Variable/OTC/NotoSansCJK-VF.otf.ttc
To see this behavior, need to patch the following change to the ftview.c
Repro Step:
- Build FreeType and Demos.
- Launch
ftview
by following command
./bin/ftview 32 NotoSansCJK-VF.otf.ttc
- See the RSS by following command
ps -o pid,rss,command -p <pid of ftview>
- Apply attached patch to the
ftview.c
and build demos.
- Launch
ftview
with the same command as above.
./bin/ftview 32 NotoSansCJK-VF.otf.ttc
- See the RSS by following command.
ps -o pid,rss,command -p <pid of ftview>
Then, we can observe the heap allocation.
The allocation happened in tt_var_load_item_variation_store
function in src/truetype/ttgxvar.c
.
https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/src/truetype/ttgxvar.c#L684
/* Parse delta set. */
/* */
/* On input, deltas are (word_delta_count + region_idx_count) bytes */
/* each if `long_words` isn't set, and twice as much otherwise. */
/* */
/* On output, deltas are expanded to `region_idx_count` shorts each. */
if ( FT_NEW_ARRAY( varData->deltaSet, item_count * region_idx_count ) )
goto Exit;
varData->itemCount = item_count;
Here, the size of deltaSet
is 8
on my environment, and item_count
is 65535
since CJK font has maximum glyph count.
Therefore, the total allocation is about 500kb (8 * 65535)
.
Looks like the sub region of this deltaSet
is used for tt_var_get_item_delta
.
Can this be loading the only necessary region of deltaSet
in tt_var_get_item_delta
?