slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.55k stars 601 forks source link

slint is using too much thread-local storage space #3551

Closed ilmai closed 10 months ago

ilmai commented 1 year ago

I'm working on a crate to use slint with audio plugins, and I'm running into the thread-local storage limit of libc. Apparently libc only allocates 2048 bytes for thread-local storage to use by dylibs, and slint is using approximately 1600 bytes. Here's a dump of slint symbols in the .tbss and .tdata sections in my compiled plugin. Size is the fourth column and it's in hexadecimal:

00000000000002b0 l       .tbss  0000000000000060 i_slint_renderer_skia::textlayout::FONT_CACHE::__getit::__KEY::he1f47db46a162f97
00000000000003d8 l       .tbss  0000000000000098 i_slint_core::graphics::image::cache::IMAGE_CACHE::__getit::__KEY::h0ec8c5406627c21b
0000000000000470 l       .tbss  0000000000000020 i_slint_core::properties::CURRENT_BINDING::FOO::__getit::__KEY::h5b10adb64d191408
0000000000000490 l       .tbss  0000000000000020 i_slint_core::platform::PLATFORM_INSTANCE::__getit::__KEY::h57187223f24bf85d
0000000000000518 l       .tbss  0000000000000018 i_slint_core::animations::CURRENT_ANIMATION_DRIVER::__getit::__KEY::h598854421dba08b0
00000000000004b0 l       .tbss  0000000000000068 i_slint_core::timers::CURRENT_TIMERS::__getit::__KEY::he13d5938cca7b45e
0000000000000338 l       .tbss  00000000000000a0 i_slint_compiler::typeregister::BUILTIN_ENUMS::__getit::__KEY::hd379598ab27bf5ab
0000000000000530 l       .tbss  00000000000000f8 i_slint_common::sharedfontdb::FONT_DB::__getit::__KEY::h4323777d199d051c
0000000000000000 l       .tdata 0000000000000248 i_slint_compiler::typeregister::EXPORT_STRUCTS::__getit::__KEY::h03aa90c4bae06d72

An obvious solution would be to box some of these to reduce data use to 32 bytes per object, if that's ok for performance.

ogoffart commented 1 year ago

The EXPORT_STRUCTS is gone with #3563 which seems to be the bigger one

I think it'd still make sense to box the caches.

(In a ideal world, i'd say it would be better if these cache where not thread-local but part of some kind of SlintContext or SlintApplication or something like that)

ogoffart commented 10 months ago

I'm going to close this issue because the actual problem is solved and we now use much less thread_storage space.

the remaining ones could go in the SlintContext later: https://github.com/slint-ui/slint/issues/4294