servo / servo/font-kit

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

Open
#270 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
840
Forks
137
Avg merge
4h 56m
Merged PRs (30d)
1

Description

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 : https://github.com/pmnxis/chama-optics/issues/5

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the macOS memory growth with SystemSource::all_fonts(), then inspect CoreTextSource and create_handles_from_core_text_collection, especially the font_kit::utils::slurp_file path shown in the call graph. Confirm that all_fonts() still returns the expected handles while substantially reducing peak memory usage, and add or run a regression check if the relevant test location is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, rust
Domain
desktop, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.