Files
komorebi/komorebi-bar
LGUG2Z 1c699ed4c4 perf(bar): reduce cpu usage by sticking to logical pixels
This was debugged by Lando Calrissian on Discord who submitted this text
patch. The rest of this commit message is from Lando's investigation
summary shared on Discord:

Every frame, the update() method checks if egui's window rect matches
the stored size_rect. The comparison code multiplied egui's outer_rect
(which is in logical pixels) by scale_factor, producing physical pixel
values (e.g., 3584x40 on a 2x Retina display). But size_rect stores
logical pixel values (1792x20). These can never match on a HiDPI
display, so every frame:

1. `size_rect != current_rect` evaluates to `true`
2. `position_bar()` is called, sending `ViewportCommand::OuterPosition`
   and `ViewportCommand::InnerSize`
3. Each `send_viewport_cmd` internally calls `request_repaint()` in egui
4. egui schedules another frame → go to step 1

Result: 120fps continuous rendering, consuming ~12% CPU.

Debugging Method:

Instrumented the code with frame counters, FPS tracking, and repaint
cause logging. Systematically disabled components (repaint thread,
komorebi notifications, widget rendering) to isolate the cause. Traced
egui's repaint causes to context.rs:3853 (send_viewport_cmd_to), then
found the size_rect mismatch firing 1112 times in 10 seconds.

Fix:

Removed the erroneous scale_factor multiplication from the rect
comparison, since outer_rect already reports in logical pixels — the
same coordinate space as size_rect.

Result:

┌────────────┬───────────┬───────────────────┐
│   Metric   │  Before   │       After       │
├────────────┼───────────┼───────────────────┤
│ CPU (idle) │ 12-13%    │ 0.0-0.1%          │
├────────────┼───────────┼───────────────────┤
│ Frames/sec │ 120       │ ~1 (timer-driven) │
├────────────┼───────────┼───────────────────┤
│ CPU spikes │ Up to 20% │ None observed     │
└────────────┴───────────┴───────────────────┘
2026-02-16 10:13:15 -08:00
..