summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2026-01-25 17:11:45 +0100
committerLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2026-01-25 17:11:45 +0100
commit2a14b4c401ecc1d98d65c09271a8656ccfebc4ec (patch)
treed9221867247168e4036518357d90a09b6429acd2 /src/main.rs
parent1c17d0e09b4eb837a9217a6836d964eb86d9e9b8 (diff)
downloadbibata-cursor-cli-2a14b4c401ecc1d98d65c09271a8656ccfebc4ec.tar.gz
bibata-cursor-cli-2a14b4c401ecc1d98d65c09271a8656ccfebc4ec.tar.bz2
bibata-cursor-cli-2a14b4c401ecc1d98d65c09271a8656ccfebc4ec.tar.lz
bibata-cursor-cli-2a14b4c401ecc1d98d65c09271a8656ccfebc4ec.zip

fix: improve performance without mutlithreading by ~50x

this is done by LazyLocking the system fonts loading code

performance increase was done by comparing the output of time target/release/batacli on a 64GB DDR4 RAM, Linux x86_64 system with an NVME SSD. raw results:

  • this commit: 4.93s user 2.54s system 98% cpu 7.561 total
  • previous commit: 63.19s user 307.15s system 97% cpu 6:18.31 total
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index fed8090..45d459b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,4 @@
-use std::{fs, io::Result, os::unix};
+use std::{fs, io::Result, os::unix, sync::LazyLock};
use serde::{Deserialize, Serialize};
use tiny_skia::Pixmap;
@@ -55,18 +55,14 @@ pub struct BibataColourScheme<'a> {
pub watch_opacity: f32,
}
-fn vector_to_pixmap(svg_data: &[u8]) -> Pixmap {
- let tree = {
- let mut opt = usvg::Options::default();
- // Get file's absolute directory.
- // opt.resources_dir = std::fs::canonicalize(&args[1])
- // .ok()
- // .and_then(|p| p.parent().map(|p| p.to_path_buf()));
-
- opt.fontdb_mut().load_system_fonts();
+static USVG_OPTIONS: LazyLock<usvg::Options> = LazyLock::new(||{
+ let mut opt = usvg::Options::default();
+ opt.fontdb_mut().load_system_fonts();
+ opt
+});
- usvg::Tree::from_data(svg_data, &opt).unwrap()
- };
+fn vector_to_pixmap(svg_data: &[u8]) -> Pixmap {
+ let tree = usvg::Tree::from_data(svg_data, &*USVG_OPTIONS).unwrap();
let pixmap_size = tree.size().to_int_size();
let mut pixmap = tiny_skia::Pixmap::new(pixmap_size.width(), pixmap_size.height()).unwrap();