perf: complete render-cache adoption in PassPolarPlotControl#48
Open
g4dpz wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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 viaClear(). - Updated
PassPolarPlotControldrawing paths to use cachedBrush/Peninstances (including round-cap pens for pass segments). - Added
FormattedTextCacheusage for N/E/S/W labels and introduced aFormattedTextCache.Get(string, double, Color)overload. - Added new unit/property tests validating
GetRoundCapPencaching 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)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.