Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very slow startup due to font-kit crate asking fontconfig to scan all system fonts #351

Closed
nyanpasu64 opened this issue May 19, 2020 · 1 comment
Labels
question Further information is requested
Milestone

Comments

@nyanpasu64
Copy link

nyanpasu64 commented May 19, 2020

Trying out iced 0.1.1 "clock" example on Linux OpenSUSE Tumbleweed.

On every startup, the app 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

This happens both with and without gdb. Other iced examples (not just clock) take a similarly long time to start, and get stuck in fontconfig functions.

(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/git.luolix.top-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/git.luolix.top-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

Investigation

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.

Versions

All of these issues occur on both iced 0.1.1 and master 3344850 (2020-05-15).

iced-wgpu depends on font-kit 0.6.0. Editing it to use font-kit 0.7.0 didn't resolve the slow startup:

https://github.com/hecrj/iced/blob/33448508a524db6447b380cc236be6f0d5ca8a86/wgpu/Cargo.toml#L21

@hecrj
Copy link
Member

hecrj commented May 19, 2020

Thanks for the detailed issue!

This is probably related to missing up-to-date fontconfig development libraries. See #199 and #58.

@hecrj hecrj added the question Further information is requested label May 19, 2020
@hecrj hecrj added this to the 0.2.0 milestone May 19, 2020
@hecrj hecrj modified the milestones: 0.2.0, 0.3.0 Nov 26, 2020
@hecrj hecrj modified the milestones: 0.3.0, 0.4.0 Mar 31, 2021
@hecrj hecrj closed this as completed Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants