Skip to content

perf: complete render-cache adoption in PassPolarPlotControl#48

Open
g4dpz wants to merge 1 commit into
magicbug:mainfrom
g4dpz:opt/polar-plot-cache
Open

perf: complete render-cache adoption in PassPolarPlotControl#48
g4dpz wants to merge 1 commit into
magicbug:mainfrom
g4dpz:opt/polar-plot-cache

Conversation

@g4dpz

@g4dpz g4dpz commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

PR 8: Complete render-cache adoption in PassPolarPlotControl
Summary
Routes all per-frame Pen, Brush, and FormattedText allocations in PassPolarPlotControl through the existing _renderCache and a new _textCache, eliminating ~20 heap allocations per frame.

Changes
Added GetRoundCapPen(Color, double) to RenderResourceCache (with LineCap = Round, LineJoin = Round) for pass path segments
Segment loop: replaced new Pen(...) with _renderCache.GetRoundCapPen(color, 2.5)
DrawHorizonDisk: uses _renderCache.GetBrush(...) and _renderCache.GetPen(...)
DrawElevationRing: uses _renderCache.GetPen(...) / GetDashedPen(...) for dashed variant
DrawAzimuthSpokes: uses _renderCache.GetPen(palette.SkyPlotSpoke, 1)
DrawHoverMarker: uses _renderCache.GetBrush(...) and _renderCache.GetPen(...) for all three drawing calls
DrawCardinalLabels: added FormattedTextCache _textCache for N/E/S/W labels
Converted static drawing methods to instance methods for cache access
Clear() updated to include _roundCapPens dictionary
Testing
3 property-based tests: GetRoundCapPen returns same reference, has round cap/join, correct thickness/colour
2 unit tests: Clear() invalidates entries, different colours produce different pens
Full suite passes (1148 tests)
No behaviour change
Pixel-identical rendering output. The cache is purely an acceleration layer — same pens and brushes, just reused between frames.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Completes render-cache usage in PassPolarPlotControl by routing per-frame Brush/Pen allocations through RenderResourceCache and caching cardinal-direction FormattedText to reduce heap allocations during rendering.

Changes:

  • Added RenderResourceCache.GetRoundCapPen(Color, double) and clears its cache via Clear().
  • Updated PassPolarPlotControl drawing paths to use cached Brush/Pen instances (including round-cap pens for pass segments).
  • Added FormattedTextCache usage for N/E/S/W labels and introduced a FormattedTextCache.Get(string, double, Color) overload.
  • Added new unit/property tests validating GetRoundCapPen caching and configuration.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
OscarWatch/Controls/RenderResourceCache.cs Adds round-cap pen caching and ensures it is cleared with other cached resources.
OscarWatch/Controls/PassPolarPlotControl.cs Switches rendering to cached resources and adds formatted-text caching for cardinal labels.
OscarWatch/Controls/FormattedTextCache.cs Adds overload to cache FormattedText using an explicit foreground Color.
OscarWatch.Tests/Performance/PassPolarPlotRenderCacheTests.cs Adds tests covering round-cap pen caching correctness and cache invalidation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +229 to 233
private void DrawLabel(DrawingContext context, string text, double x, double y, UiPalette palette)
{
var ft = new FormattedText(
text,
System.Globalization.CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(FontFamily.Default, FontStyle.Normal, FontWeight.SemiBold),
12,
new SolidColorBrush(palette.SkyPlotLabel));
var ft = _textCache.Get(text, 12, palette.SkyPlotLabel);
context.DrawText(ft, new Point(x, y));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants