Use multiple threads for Relm async tasks depending on system

This commit is contained in:
Reinout Meliesie 2026-01-21 17:24:36 +01:00
commit 2014c83224
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6

View file

@ -4,6 +4,9 @@ mod persist;
mod ui; mod ui;
mod views; mod views;
use std::cmp::max;
use std::thread;
use gtk4::gdk::Display; use gtk4::gdk::Display;
use gtk4::gio::File; use gtk4::gio::File;
use gtk4::{CssProvider, Settings, gio}; use gtk4::{CssProvider, Settings, gio};
@ -18,8 +21,13 @@ fn main() {
include_app_css(); include_app_css();
// TODO: Set this to nr of cores if using Relm commands heavily. // Set number of threads used by Relm for async tasks to the number of available
// RELM_THREADS.set(4).unwrap(); // CPU cores minus two, thereby reserving one for the main thread and one for
// the database connection thread spawned by async_sqlite.
let cores = thread::available_parallelism()
.map(|cores| cores.get() - 2)
.unwrap_or(1);
relm4::RELM_THREADS.set(max(cores, 1)).unwrap();
app.run::<App>(()); app.run::<App>(());
} }