From 96ac1ee65da31055704e0a14cafacc33914d7e86 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 30 Sep 2026 19:56:48 +0200 Subject: perf(dashboard): draw at 0.1s only while the dashboard is visible Conky gives Lua no way to request one redraw, so a scroll showed up to 2s late. Pointer enter and leave, which Hyprland sends on every toggle of the special workspace, now switch conky_set_update_interval between 0.1s and the config's 2s. At that rate the CPU and network counters would sample over 0.1s windows and the chart would fill 20x faster, so both now sample through data.new_gate on the /proc/uptime clock, about every 2s, and redraw their last values in between. The samplers move to texeci: execi runs in the main loop and a 0.7s nvtable or an Immich download stalled the scroll. Measured: about 12% of one core while visible, 0.5% while hidden. Co-Authored-By: Claude Opus 5.5 --- widgets/network.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'widgets/network.lua') diff --git a/widgets/network.lua b/widgets/network.lua index 3a11521..20b0573 100644 --- a/widgets/network.lua +++ b/widgets/network.lua @@ -37,6 +37,11 @@ local rx_hist, tx_hist = {}, {} local hist_len = 0 local lan_addr = nil +-- Sampled every ~2s whatever the draw rate, so the chart keeps one point per +-- sample rather than per draw. 1.9 not 2: draws jitter by a few ms. +local gate = data.new_gate(1.9) +local down, up = nil, nil + -- Append to a fixed-length history, dropping the oldest. A plain array with -- table.remove(1) rather than a circular buffer with an index: the lengths -- here are a few hundred at most and the draw is every two seconds, so the @@ -73,8 +78,11 @@ function M.draw(cr, rect, colors) rx_counter = rx_counter or data.new_rate_counter(interval) tx_counter = tx_counter or data.new_rate_counter(interval) - local down = rx_counter:sample(read_counter('rx_bytes')) - local up = tx_counter:sample(read_counter('tx_bytes')) + local sampled, now = gate() + if sampled then + down = rx_counter:sample(read_counter('rx_bytes'), now) + up = tx_counter:sample(read_counter('tx_bytes'), now) + end -- Fluid type, as every other card does: one base size S drives everything, -- taken as the smaller of a height budget and a measured width fit. @@ -140,8 +148,8 @@ function M.draw(cr, rect, colors) while #rx_hist > hist_len do table.remove(rx_hist, 1) end while #tx_hist > hist_len do table.remove(tx_hist, 1) end end - if down then push(rx_hist, down, hist_len) end - if up then push(tx_hist, up, hist_len) end + if sampled and down then push(rx_hist, down, hist_len) end + if sampled and up then push(tx_hist, up, hist_len) end -- One ceiling for both series. Scaled independently they would lie about -- their relative size, which is the entire reason to draw them together. -- cgit v1.2.3