Cache per-output palettes instead of re-parsing them every frame #5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/cache-per-output-palette"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Audit finding #6 (Medium, perf)
state.rspalette_for_surfacecalledbread_theme::load_palette_for(&name)— a blocking file read plus JSON parse — from insideredraw_surface, whichredraw_alldrives at 60fps during the entrance / unlock / breath animations and on every 1s clock tick, once per surface, times N monitors.Change
AppState.output_palettes: aRefCell<HashMap<String, Palette>>caching the resolved palette perwl_outputname.palette_for_surfacereads it, populating on first use.RefCellbecause the call sits in the&self-shaped middle ofredraw_surfacewith other&selfborrows live; the event loop is single-threaded so there's no aliasing risk.theme_watch.rs: anotifywatcher on the runtimebread/palettes/andbread/themes/directories, bridged onto the calloop event loop through acalloop::channel— the same patternstatus.rsandauth.rsalready use for D-Bus and PAM. On a palette/theme file change it clears the cache and repaints once, so live per-monitor recolouring (new wallpaper,bread-theme reload,breadpaper set_on) still works.theme_watchisNoneandpalette_for_surfacefalls back to the previous per-call disk read. Correctness never regresses; only the fast path is lost..<name>.tmp.<pid>scratch filesbread-theme's atomic writes create, reacting only to the final*.json/*.css. Unit-tested.New dependency
notify = "7"(already used elsewhere in the ecosystem, e.g. bos-settings). Pullsinotify+ a handful of small support crates. An alternative would be enabling calloop's owninotifyfeature for a lighter tree;notifywas chosen for consistency with the rest of the ecosystem and its graceful cross-platform degradation.Tests
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspace --all-targets(140 tests),cargo build --release --locked— all pass.