Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.

Commit ee93332

Browse files
committed
daemon: use smallvec for storing some data
Because we mostly store a small number of items, `smallvec` can actually be very nice for us.
1 parent c754001 commit ee93332

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

daemon/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ log = { version = "0.4", default-features = false, features = [
1818
"release_max_level_info",
1919
"std",
2020
] }
21-
rustix = { version = "1.1", default-features = false, features = ["event"] }
21+
rustix = { version = "1.1", default-features = false, features = [ "event" ] }
2222
libc = "0.2"
2323
keyframe = "1.1"
2424
sd-notify = { version = "0.4" }
25+
smallvec = { version = "1.15", default-features = false, features = [ "union" ] }
2526

2627
[build-dependencies]
2728
waybackend-scanner = { version = "0.7", features = ["build-script"] }

daemon/src/animations.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use log::error;
2+
use smallvec::SmallVec;
23
use waybackend::{Waybackend, objman::ObjectManager};
34

45
use std::time::{Duration, Instant};
@@ -15,7 +16,7 @@ mod transitions;
1516
use transitions::Effect;
1617

1718
pub struct Animator {
18-
pub wallpapers: Vec<WallpaperCell>,
19+
pub wallpapers: SmallVec<[WallpaperCell; 2]>,
1920
now: Instant,
2021
animator: AnimatorKind,
2122
}
@@ -27,7 +28,7 @@ enum AnimatorKind {
2728

2829
impl Animator {
2930
pub fn new(
30-
mut wallpapers: Vec<WallpaperCell>,
31+
mut wallpapers: SmallVec<[WallpaperCell; 2]>,
3132
transition: &ipc::Transition,
3233
img_req: ImgReq,
3334
animation: Option<ipc::Animation>,
@@ -157,7 +158,7 @@ impl Animation {
157158
&mut self,
158159
backend: &mut Waybackend,
159160
objman: &mut ObjectManager<WaylandObject>,
160-
wallpapers: &mut Vec<WallpaperCell>,
161+
wallpapers: &mut SmallVec<[WallpaperCell; 2]>,
161162
pixel_format: PixelFormat,
162163
) {
163164
let Self {

daemon/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustix::{
1414
fs::Timespec,
1515
};
1616

17+
use smallvec::SmallVec;
1718
use wallpaper::WallpaperCell;
1819

1920
use waybackend::{Global, objman, types::ObjectId};
@@ -58,7 +59,7 @@ struct Daemon {
5859
layer_shell: ObjectId,
5960
layer: Layer,
6061
pixel_format: PixelFormat,
61-
wallpapers: Vec<WallpaperCell>,
62+
wallpapers: SmallVec<[WallpaperCell; 2]>,
6263
animators: Vec<Animator>,
6364
namespace: String,
6465
use_cache: bool,
@@ -115,7 +116,7 @@ impl Daemon {
115116
layer_shell,
116117
layer: args.layer,
117118
pixel_format: args.format.unwrap_or(PixelFormat::Argb),
118-
wallpapers: Vec::with_capacity(1),
119+
wallpapers: SmallVec::new(),
119120
animators: Vec::with_capacity(1),
120121
namespace: args.namespace,
121122
use_cache: !args.no_cache,
@@ -224,7 +225,7 @@ impl Daemon {
224225
.collect()
225226
}
226227

227-
fn find_wallpapers_by_names(&self, names: &[MmappedStr]) -> Vec<WallpaperCell> {
228+
fn find_wallpapers_by_names(&self, names: &[MmappedStr]) -> SmallVec<[WallpaperCell; 2]> {
228229
self.wallpapers
229230
.iter()
230231
.filter_map(|wallpaper| {
@@ -284,7 +285,7 @@ impl Daemon {
284285
}
285286

286287
fn commit_pending_surface_changes(&mut self) {
287-
let mut to_stop = Vec::with_capacity(self.wallpapers.len());
288+
let mut to_stop = SmallVec::<[WallpaperCell; 2]>::with_capacity(self.wallpapers.len());
288289
for wallpaper in &self.wallpapers {
289290
if wallpaper.borrow_mut().commit_surface_changes(
290291
&mut self.backend,

daemon/src/wallpaper/bump_pool.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use common::{ipc::PixelFormat, mmap::Mmap};
2+
use smallvec::SmallVec;
23
use waybackend::{Waybackend, objman::ObjectManager, types::ObjectId};
34

45
use crate::wayland::{wl_shm, wl_shm_pool};
@@ -62,10 +63,10 @@ impl Buffer {
6263
pub struct BumpPool {
6364
pool_id: ObjectId,
6465
mmap: Mmap,
65-
buffers: Vec<Buffer>,
66+
buffers: SmallVec<[Buffer; 2]>,
6667
/// This for when resizes happen, where we cannot delete a buffer before it was released by the
6768
/// compositor, least undefined behavior happens
68-
dead_buffers: Vec<ObjectId>,
69+
dead_buffers: SmallVec<[ObjectId; 4]>,
6970
width: i32,
7071
height: i32,
7172
last_used_buffer: usize,
@@ -89,8 +90,8 @@ impl BumpPool {
8990
Self {
9091
pool_id,
9192
mmap,
92-
buffers: Vec::with_capacity(2),
93-
dead_buffers: Vec::with_capacity(1),
93+
buffers: SmallVec::new(),
94+
dead_buffers: SmallVec::new(),
9495
width,
9596
height,
9697
last_used_buffer: 0,

0 commit comments

Comments
 (0)