Repository navigation
Description
🤖 This pull request was created by Repo Assist, an automated AI assistant.
Summary
Two allocations in high-frequency hotpaths are eliminated.
1. Hole-punch geometry caching (MainWindow.xaml.cs)
ApplyHolePunchEffect is invoked on every mouse-move event while the application is running. Previously it created two new heap objects each call:
| Object | Old | New |
|---|---|---|
EllipseGeometry (hole under cursor) |
new every move |
created once, Center updated in place |
CombinedGeometry (base minus hole) |
new every move |
created once, reused |
Each context (main window + every additional monitor window) gets its own cached geometry pair stored in _mainHoleGeometry/_mainPunchedGeometry (main) or MonitorWindowContext.HoleGeometry/PunchedGeometry (monitors). The cache is invalidated (set to null) in CreateFrameGeometry so it rebuilds correctly after a window resize.
Impact: On a typical 60 Hz or 125 Hz mouse, this eliminates ~120–250 short-lived object pairs per second, noticeably reducing GC minor-collection frequency during active use.
2. JsonSerializerOptions caching (AppSettings.cs)
AppSettings.Save() (called on every brightness or colour-temperature change) previously allocated a fresh JsonSerializerOptions each time. The options object is now a static readonly field.
Root cause
Both allocations were unnecessary; the objects are value-stable across calls.
Trade-offs
EllipseGeometryis a WPFDependencyObject; settingCenterin place correctly invalidates the render tree, so visual behaviour is identical.- Cache is per-context, so multi-monitor scenarios behave correctly.
- No behaviour change to settings serialisation.
Test Status
| Step | Result |
|---|---|
dotnet build /p:EnableWindowsTargeting=true |
✅ 0 errors, 0 warnings |
Note
🔒 Integrity filter blocked 1 item
The following item were blocked because they don't meet the GitHub integrity level.
- Detect camera is being used by another application and automatically turn on #21
list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
To allow these resources, lower min-integrity in your GitHub frontmatter:
tools:
github:
min-integrity: approved # merged | approved | unapproved | noneGenerated by Repo Assist · ● 4.6M · ◷
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-geometry-cache-2026-07-14-562ebb5dda852a02.
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 (166 of 166 lines)
From 5d1ea08e1f3193affb9d190ca9d2caaa1999d646 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Tue, 14 Jul 2026 13:16:54 +0000
Subject: [PATCH] perf: cache hole-punch geometries and JsonSerializerOptions
to reduce GC pressure
Two optimisations targeting the highest-frequency hotpaths:
1. ApplyHolePunchEffect (called on every mouse-move event while the app
is running) previously created two new heap objects per call:
- EllipseGeometry (the transparent circular hole under the cursor)
- CombinedGeometry (baseGeometry minus the hole)
Now a pair of geometry objects is created once per context (main window
+ each additional monitor window) and reused. On subsequent mouse moves
only EllipseGeometry.Center is updated in place, which invalidates the
WPF render tree without any heap allocation. The cached pair is reset
to null whenever CreateFrameGeometry() rebuilds the base geometry.
2. AppSettings.Save() previously allocated a new JsonSerializerOptions
instance on every call. Brightness/colour-temperature adjustments save
on every change, so rapid adjustments (held key, slider drag) caused
repeated unnecessary allocations. The options object is now a static
readonly field.
Build: 0 errors, 0 warnings (net10.0-windows, EnableWindowsTargeting=true)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
WindowsEdgeLight/AppSettings.cs | 7 ++---
WindowsEdgeLight/MainWindow.xaml.cs | 43 ++++++++++++++++++++++++-----
2 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/WindowsEdgeLight/AppSettings.cs b/WindowsEdgeLight/AppSettings.cs
index 1f46de9..21d2514 100644
--- a/WindowsEdgeLight/AppSettings.cs
+++ b/WindowsEdgeLight/AppSettings.cs
@@ -101,6 +101,8 @@ public class AppSettings
return new AppSettings();
}
+ private static readonly JsonSerializerOptions _writeOptions = new JsonSerializerOptions { WriteIndented = true };
+
... (truncated)
Activity
shanselman commentedon Aug 8, 2026
Superseded by the focused #158 geometry cache and #162 settings work.