Skip to content

core_text's all_fonts() occurs heavy memory usage in macOS #270

@pmnxis

Description

@pmnxis

When using SystemSource::all_fonts() in macOS, Memory usage is over 1GB

let sys_src = SystemSource::new();
if let Ok(result) = sys_src.all_fonts() {
    for handle in result {
 ...

Here's malloc call graph when using SystemSource::all_fonts()

Analysis Tool:   /Applications/Xcode.app/Contents/Developer/usr/bin/malloc_history
Analysis Tool Version:  Xcode 26.2 (17C52)

Physical footprint:         945.6M
Physical footprint (peak):  1.2G
Idle exit:                  untracked
----

VM region sizes shown as dirty + swapped/compressed - purgableVolatile.

Stack logging was dynamically enabled in target process after it was launched so no backtraces are available for earlier allocations.
Stack logging was enabled for 6.0 seconds, which is 79.2% of the process's total lifetime of 7.6 seconds.

Malloc blocks with no stack:    541   total size: 34K
   VM regions with no stack:     40   total size: 20.1M

Call graph:
    72284 (1864M) << TOTAL >>
      45153 (1769M) thread_start  (in libsystem_pthread.dylib) + 8  [0x19920eb80]
      + 45153 (1769M) _pthread_start  (in libsystem_pthread.dylib) + 136  [0x199213bc8]
      +   44597 (1769M) std::sys::thread::unix::Thread::new::thread_start::h98270432b6aefc44  (in chama-optics) + 52  [0x1038121bc]
      +   ! 44427 (1769M) core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h9e53cc9001859dc6  (in chama-optics) + 24  [0x102ab92d0]
      +   ! : 44425 (1769M) std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::hb7d0a81e89127a15  (in chama-optics) + 628  [0x10279d1e8]
      +   ! : | 44425 (1769M) __rust_try  (in chama-optics) + 32  [0x10279e204]
      +   ! : |   44425 (1769M) std::panicking::catch_unwind::do_call::h791d1b1db80d21d9  (in chama-optics) + 52  [0x10290a064]
      +   ! : |     44425 (1769M) _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hfe719bf1aa300b16  (in chama-optics) + 44  [0x102909b14]
      +   ! : |       44424 (1769M) std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::hd59f0c9835f76a46  (in chama-optics) + 100  [0x10279dfc4]
      +   ! : |       + 44424 (1769M) std::sys::backtrace::__rust_begin_short_backtrace::h891a677ff39ec149  (in chama-optics) + 24  [0x102d1631c]
      +   ! : |       +   44424 (1769M) chama_optics::fonts::font_unify::FontsUnify::new::_$u7b$$u7b$closure$u7d$$u7d$::hc885bef225c8ad76  (in chama-optics) + 164  [0x102caafe8]
      +   ! : |       +     247 (1689M) font_kit::sources::core_text::create_handles_from_core_text_collection::he50369d58997caa3  (in chama-optics) + 584  [0x103193a2c]
      +   ! : |       +     ! 247 (1689M) font_kit::utils::slurp_file::h58ca4e6807b38677  (in chama-optics) + 100  [0x1031949e0]
      +   ! : |       +     !   247 (1689M) alloc::raw_vec::RawVecInner$LT$A$GT$::try_allocate_in::hc31c6f5b471e76d6  (in chama-optics) + 196  [0x1031956a4]
      +   ! : |       +     !     247 (1689M) _malloc_zone_malloc_instrumented_or_legacy  (in libsystem_malloc.dylib) + 268  [0x1990450f4]

It's too heavy,.. So I think therefore need to fix the memory usage on CoreTextSource.

Related Issue : pmnxis/chama-optics#5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions