perf(memory): optimize C++ string operations to reduce heap fragmentation

- Replaced pass-by-value std::string parameters with const std::string&
or std::string_view to prevent SSO overallocations.

- Refactored static mapping functions in UPower to return
std::string_view instead of constructing std::string literals, enabling
perfect cache locality.

- Optimized string concatenation in hot loops (network IPs, inhibitor
lists, sway window marks) by using std::string::append() and
pre-reserving capacity instead of overloaded operator+ which produces
temporary heap instances.

These optimizations reduce high-frequency memory churn and overall heap
fragmentation within the main rendering loops.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman
2026-03-02 21:51:32 -06:00
parent fd086d0f33
commit 4c71b2bf9f
24 changed files with 43 additions and 38 deletions

View File

@@ -3,10 +3,10 @@
#include <glibmm/dispatcher.h>
#include <sigc++/signal.h>
#include <cstddef>
#include <functional>
#include <mutex>
#include <queue>
#include <cstddef>
#include <thread>
#include <tuple>
#include <type_traits>

View File

@@ -72,8 +72,7 @@ class SleeperThread {
std::unique_lock lk(mutex_);
CancellationGuard cancel_lock;
return condvar_.wait(lk, [this] {
return signal_.load(std::memory_order_relaxed) ||
!do_run_.load(std::memory_order_relaxed);
return signal_.load(std::memory_order_relaxed) || !do_run_.load(std::memory_order_relaxed);
});
}
@@ -87,8 +86,7 @@ class SleeperThread {
wait_end = now + dur;
}
return condvar_.wait_until(lk, wait_end, [this] {
return signal_.load(std::memory_order_relaxed) ||
!do_run_.load(std::memory_order_relaxed);
return signal_.load(std::memory_order_relaxed) || !do_run_.load(std::memory_order_relaxed);
});
}
@@ -98,8 +96,7 @@ class SleeperThread {
std::unique_lock lk(mutex_);
CancellationGuard cancel_lock;
return condvar_.wait_until(lk, time_point, [this] {
return signal_.load(std::memory_order_relaxed) ||
!do_run_.load(std::memory_order_relaxed);
return signal_.load(std::memory_order_relaxed) || !do_run_.load(std::memory_order_relaxed);
});
}