iced icon indicating copy to clipboard operation
iced copied to clipboard

Slow startup on Linux due to font loading of **all** the system fonts in `/usr/share/fonts`

Open abique opened this issue 1 month ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues.

Is this issue related to iced?

  • [X] My hardware is compatible and my graphics drivers are up-to-date.

What happened?

The application was slow to start on Linux, especially in debug.

What is the expected behavior?

Fast startup as I could experience on macOS.

Version

master

Operating System

Linux

Do you have any log output?

Here's the stacktrace in question:
core::result::Result<&T,E>::copied::{{closure}} (Unknown Source:0)
core::result::Result<T,E>::map (Unknown Source:0)
core::result::Result<&T,E>::copied (Unknown Source:0)
core::array::<impl core::convert::TryFrom<&[T]> for [T; N]>::try_from (Unknown Source:0)
<T as core::convert::TryInto<U>>::try_into (Unknown Source:0)
<u32 as ttf_parser::parser::FromData>::parse (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ttf-parser-0.19.2/src/parser.rs:80)
<ttf_parser::Magic as ttf_parser::parser::FromData>::parse (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ttf-parser-0.19.2/src/lib.rs:139)
core::ops::function::FnOnce::call_once (Unknown Source:0)
core::option::Option<T>::and_then (Unknown Source:0)
ttf_parser::parser::Stream::read (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ttf-parser-0.19.2/src/parser.rs:741)
ttf_parser::fonts_in_collection (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ttf-parser-0.19.2/src/lib.rs:2153)
fontdb::Database::load_fonts_from_file (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fontdb-0.15.0/src/lib.rs:236)
fontdb::Database::load_font_file_impl (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fontdb-0.15.0/src/lib.rs:269)
fontdb::Database::load_font_file (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fontdb-0.15.0/src/lib.rs:260)
fontdb::Database::load_fonts_dir_impl (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fontdb-0.15.0/src/lib.rs:321)
fontdb::Database::load_fonts_dir (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fontdb-0.15.0/src/lib.rs:303)
fontdb::Database::load_fonts_dir_impl (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fontdb-0.15.0/src/lib.rs:329)
fontdb::Database::load_fonts_dir (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fontdb-0.15.0/src/lib.rs:303)
fontdb::Database::load_fontconfig (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fontdb-0.15.0/src/lib.rs:486)
fontdb::Database::load_system_fonts (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fontdb-0.15.0/src/lib.rs:396)
cosmic_text::font::system::FontSystem::load_fonts (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cosmic-text-0.10.0/src/font/system.rs:171)
cosmic_text::font::system::FontSystem::new_with_fonts (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cosmic-text-0.10.0/src/font/system.rs:67)
iced_graphics::text::font_system::{{closure}} (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/graphics/src/text.rs:162)
once_cell::sync::OnceCell<T>::get_or_init::{{closure}} (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/lib.rs:1120)
once_cell::imp::OnceCell<T>::initialize::{{closure}} (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/imp_std.rs:72)
core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut (Unknown Source:0)
once_cell::imp::initialize_or_wait (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/imp_std.rs:196)
once_cell::imp::OnceCell<T>::initialize (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/imp_std.rs:68)
once_cell::sync::OnceCell<T>::get_or_try_init (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/lib.rs:1161)
once_cell::sync::OnceCell<T>::get_or_init (/home/abique/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/lib.rs:1120)
iced_graphics::text::font_system (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/graphics/src/text.rs:160)
<iced_graphics::text::paragraph::Paragraph as iced_core::text::paragraph::Paragraph>::compare (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/graphics/src/text/paragraph.rs:150)
iced_core::text::paragraph::Paragraph::update (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/core/src/text/paragraph.rs:39)
iced_core::widget::text::layout::{{closure}} (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/core/src/widget/text.rs:240)
iced_core::layout::sized (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/core/src/layout.rs:126)
iced_core::widget::text::layout (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/core/src/widget/text.rs:232)
<iced_core::widget::text::Text<Theme,Renderer> as iced_core::widget::Widget<Message,Theme,Renderer>>::layout (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/core/src/widget/text.rs:181)
iced_core::layout::flex::resolve (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/core/src/layout/flex.rs:114)
<iced_widget::row::Row<Message,Theme,Renderer> as iced_core::widget::Widget<Message,Theme,Renderer>>::layout (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/widget/src/row.rs:181)
iced_core::layout::flex::resolve (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/core/src/layout/flex.rs:114)
<iced_widget::column::Column<Message,Theme,Renderer> as iced_core::widget::Widget<Message,Theme,Renderer>>::layout (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/widget/src/column.rs:192)
iced_runtime::user_interface::UserInterface<Message,Theme,Renderer>::build (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/runtime/src/user_interface.rs:98)
iced_winit::application::build_user_interface (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/winit/src/application.rs:846)
iced_winit::application::run_instance::{{closure}} (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/winit/src/application.rs:549)
iced_winit::application::run::Runner<Message,F,C>::process_event (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/winit/src/application.rs:441)
<iced_winit::application::run::Runner<Message,F,C> as winit::application::ApplicationHandler<Message>>::window_event (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/winit/src/application.rs:372)
winit::event_loop::dispatch_event_for_app (/home/abique/.cargo/git/checkouts/winit-57d3141eaf559308/8affa52/src/event_loop.rs:628)
winit::event_loop::EventLoop<T>::run_app::{{closure}} (/home/abique/.cargo/git/checkouts/winit-57d3141eaf559308/8affa52/src/event_loop.rs:262)
core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut (Unknown Source:0)
winit::platform_impl::platform::wayland::event_loop::EventLoop<T>::single_iteration (/home/abique/.cargo/git/checkouts/winit-57d3141eaf559308/8affa52/src/platform_impl/linux/wayland/event_loop/mod.rs:344)
winit::platform_impl::platform::wayland::event_loop::EventLoop<T>::pump_events (/home/abique/.cargo/git/checkouts/winit-57d3141eaf559308/8affa52/src/platform_impl/linux/wayland/event_loop/mod.rs:211)
winit::platform_impl::platform::wayland::event_loop::EventLoop<T>::run_on_demand (/home/abique/.cargo/git/checkouts/winit-57d3141eaf559308/8affa52/src/platform_impl/linux/wayland/event_loop/mod.rs:181)
winit::platform_impl::platform::EventLoop<T>::run_on_demand (/home/abique/.cargo/git/checkouts/winit-57d3141eaf559308/8affa52/src/platform_impl/linux/mod.rs:803)
winit::platform_impl::platform::EventLoop<T>::run (/home/abique/.cargo/git/checkouts/winit-57d3141eaf559308/8affa52/src/platform_impl/linux/mod.rs:796)
winit::event_loop::EventLoop<T>::run_app (/home/abique/.cargo/git/checkouts/winit-57d3141eaf559308/8affa52/src/event_loop.rs:262)
iced_winit::application::run (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/winit/src/application.rs:459)
iced::application::Application::run (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/src/application.rs:215)
iced::program::Program<P>::run_with (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/src/program.rs:247)
iced::program::Program<P>::run (/home/abique/.cargo/git/checkouts/iced-f01cba4d5e61fd0a/06ff17f/src/program.rs:171)
titan::main (/home/abique/develop/titan/src/main.rs:18)
core::ops::function::FnOnce::call_once (Unknown Source:0)
std::sys_common::backtrace::__rust_begin_short_backtrace (Unknown Source:0)
std::rt::lang_start::{{closure}} (Unknown Source:0)
std::rt::lang_start_internal (Unknown Source:0)
std::rt::lang_start (Unknown Source:0)
main (Unknown Source:0)
___lldb_unnamed_symbol3256 (Unknown Source:0)
__libc_start_main (Unknown Source:0)
_start (Unknown Source:0)

And the problem is in fontdb which loads all my fonts located in /usr/share/fonts.

I have 7 GB+ of fonts so imagine the time it'd take to scan all of it on a 10 years old computer in debug.

abique avatar Jun 04 '24 20:06 abique