servo / servo/font-kit

`SystemSource::new()` very slow on Linux, asks fontconfig to scan all system fonts

Open
#148 3 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

I recently reported https://github.com/hecrj/iced/issues/351:

When I launch any of the iced example apps, it hangs on a blank window for around 31 seconds while loading fonts. The slowness occurs in fontconfig C functions, called by the the font-kit crate. Incidentally, reloading fc-cache is also a fairly slow process taking the same "order of magnitude" time.

During the hang, the terminal prints out all sorts of funny messages: https://youtu.be/-WZaFURNJYs

(gdb) bt
#0  0x000055555600bc7c in FT_Stream_ReadFields ()
#1  0x0000555556029b9c in pcf_load_font ()
#2  0x000055555602b193 in PCF_Face_Init ()
#3  0x000055555600cd14 in open_face ()
#4  0x000055555600db15 in FT_Open_Face ()
#5  0x000055555600e086 in FT_New_Face ()
#6  0x0000555555fcb13b in FcFreeTypeQuery ()
#7  0x0000555555fc8646 in FcFileScanFontConfig ()
#8  0x0000555555fc87a1 in FcFileScanConfig ()
#9  0x0000555555fc8a56 in FcDirScanConfig ()
#10 0x0000555555fc8bb8 in FcDirCacheScan ()
#11 0x0000555555fc8da1 in FcDirCacheRead ()
#12 0x0000555555fc0092 in FcConfigAddDirList ()
#13 0x0000555555fc0162 in FcConfigBuildFonts ()
#14 0x0000555555fcdcec in FcInitLoadOwnConfigAndFonts ()
#15 0x0000555555fcdd17 in FcInitLoadConfigAndFonts ()
#16 0x0000555555f885ba in font_kit::sources::fontconfig::fc::Config::new ()
    at /home/nyanpasu64/.cargo/registry/src/github.com-1ecc6299db9ec823/font-kit-0.6.0/src/sources/fontconfig.rs:300
#17 0x0000555555f8ced9 in font_kit::sources::fontconfig::FontconfigSource::new ()
    at /home/nyanpasu64/.cargo/registry/src/github.com-1ecc6299db9ec823/font-kit-0.6.0/src/sources/fontconfig.rs:40
#18 0x0000555555b4e2fa in iced_wgpu::text::font::Source::new () at wgpu/src/text/font.rs:12
#19 0x0000555555b40321 in iced_wgpu::text::Pipeline::new (device=0x7fffffff9b08, format=wgpu_types::TextureFormat::Bgra8UnormSrgb, 
    default_font=...) at wgpu/src/text.rs:31
#20 0x0000555555af0f85 in iced_wgpu::renderer::Renderer::new (device=0x7fffffff9b08, settings=...) at wgpu/src/renderer.rs:64
#21 0x0000555555b62d4a in <iced_wgpu::window::backend::Backend as iced_native::window::backend::Backend>::new (settings=...)
    at wgpu/src/window/backend.rs:46
#22 0x00005555556bf5c8 in iced_winit::application::Application::run (settings=..., backend_settings=...)
    at /home/nyanpasu64/code/iced/winit/src/application.rs:180
#23 0x00005555556fd077 in iced::application::Application::run (settings=...) at /home/nyanpasu64/code/iced/src/application.rs:201
#24 0x00005555556f5533 in clock::main () at examples/clock/src/main.rs:8

I think this is font-kit's fault. iced-wgpu calls font_kit::source::SystemSource::new():

https://github.com/hecrj/iced/blob/33448508a524db6447b380cc236be6f0d5ca8a86/wgpu/src/text/font.rs#L12

and everything from then on is font-kit's responsibility.

Interestingly, sudo fc-cache -f only takes 6 seconds and doesn't print any funny messages. And launching kate in gdb, the call to FcConfig * FcInitLoadConfigAndFonts(void) only takes a few seconds and prints no errors to the terminal.

This issue occurs with both font-kit 0.6.0 and 0.7.0.

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 at font-kit-0.6.0's src/sources/fontconfig.rs around Config::new and trace the call from iced's wgpu/src/text/font.rs. Reproduce the delay by launching an iced example under the reported Linux/fontconfig setup, then compare the fontconfig initialization behavior with the timings in the issue. Done means the cause is identified and the excessive startup scan or delay is addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.