Repository navigation
Description
π€ This PR was created by Repo Assist, an automated AI assistant.
Summary
Three small allocation sources removed from the hot path β most noticeable when many additional monitors are connected and brightness/temperature is adjusted frequently.
Changes
AppSettings.cs
- Promote
JsonSerializerOptionsforLoad()andSave()from per-call heap allocations tostatic readonlyfields.Save()is called on every brightness/temperature change, so this avoids creating a new options object on each call.
MainWindow.xaml.cs
- Add
static readonly s_coolColor/s_warmColorβ the twoColor.FromRgb()constant values inSetColorTemperatureandUpdateAdditionalMonitorWindowsno longer allocate per-call. - Introduce
GetTemperatureColor()+_cachedTempColor/_cachedColorTemperatureβ the Lerp is only re-executed when_colorTemperatureactually changes.UpdateAdditionalMonitorWindowsis also called on every brightness change (for each additional monitor), so the temperature colour was being recomputed even when the temperature had not changed. - Extract the duplicated local
Lerpfunction (previously copy-pasted in two methods) as a singleprivate static LerpColormethod.
Behaviour
No observable change in behaviour β all visible output remains identical. The optimisation is purely internal bookkeeping.
Test Status
Build: β
0 errors, 0 warnings (dotnet build -p:EnableWindowsTargeting=true)
Tests: no test project present in the current branch of the repo.
Generated by Repo Assist Β· β 3M Β· β·
To install this agentic workflow, run
gh aw add githubnext/agentics/workflows/repo-assist.md@cbb46ab386962aa371045839fc9998ee4e97ca64
Note
This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch repo-assist/perf-color-temp-cache-2026-07-16-883eebe0f865a908.
To fix the permissions issue, go to Settings β Actions β General and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ
Show patch preview (185 of 185 lines)
From a5b21976e85a9c86abb21f5a5dfedbb9348f2a36 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Thu, 16 Jul 2026 01:17:17 +0000
Subject: [PATCH] perf: cache colour-temperature Color structs and
JsonSerializerOptions
Three allocations removed from the hot path:
1. AppSettings: promote JsonSerializerOptions for Load and Save from
per-call heap allocations to static readonly fields. Save() is
called on every brightness/temperature change, so this avoids
creating a new options object every time.
2. MainWindow: add static readonly s_coolColor / s_warmColor so the
two Color.FromRgb() calls in SetColorTemperature and
UpdateAdditionalMonitorWindows no longer allocate per-call.
3. MainWindow: introduce GetTemperatureColor() + _cachedTempColor /
_cachedColorTemperature so the Lerp is only re-executed when
_colorTemperature actually changes. UpdateAdditionalMonitorWindows
is also called on every brightness change (for each additional
monitor), so the temperature colour was being recomputed even when
the temperature had not changed.
4. MainWindow: extract the duplicate local Lerp function (previously
copy-pasted in two methods) as a private static LerpColor method.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
WindowsEdgeLight/AppSettings.cs | 23 +++++++-----
WindowsEdgeLight/MainWindow.xaml.cs | 58 +++++++++++++++--------------
2 files changed, 43 insertions(+), 38 deletions(-)
diff --git a/WindowsEdgeLight/AppSettings.cs b/WindowsEdgeLight/AppSettings.cs
index 1f46de9..3009bd5 100644
--- a/WindowsEdgeLight/AppSettings.cs
+++ b/WindowsEdgeLight/AppSettings.cs
@@ -14,6 +14,17 @@ public class AppSettings
"WindowsEdgeLight",
"settings.json");
+ private static readonly JsonSerializerOptions s_loadOptions = new()
+ {
+ AllowTrailingCommas = true,
+ ReadCommentHandling = JsonCommentHandling.Skip
+ };
+
+ pr
... (truncated)
Activity
shanselman commentedon Aug 8, 2026
Superseded by the consolidated #162 and #134 fixes.