Skip to content

[Repo Assist] perf: cache colour-temperature Color structs and JsonSerializerOptionsΒ #141

Closed as not planned

Description

@github-actions

πŸ€– 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 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 on each call.

MainWindow.xaml.cs

  • Add static readonly s_coolColor / s_warmColor β€” the two Color.FromRgb() constant values in SetColorTemperature and UpdateAdditionalMonitorWindows no longer allocate per-call.
  • Introduce GetTemperatureColor() + _cachedTempColor / _cachedColorTemperature β€” 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.
  • Extract the duplicated local Lerp function (previously copy-pasted in two methods) as a single private static LerpColor method.

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.

Click here to create the pull request

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

  1. shanselman commented on Aug 8, 2026

    @shanselman
    Owner

    Superseded by the consolidated #162 and #134 fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions