perf: Reduce allocations and eliminate delegate overhead across 5 controls#385
Open
PaulAndersonS wants to merge 1 commit into
Open
perf: Reduce allocations and eliminate delegate overhead across 5 controls#385PaulAndersonS wants to merge 1 commit into
PaulAndersonS wants to merge 1 commit into
Conversation
…trols 1. CartesianAxisLayout.GetAxisByName — Replace LINQ query + ToList() with simple foreach loop, eliminating list allocation just to get first match. 2. Calendar MonthView special dates lookup — Replace FirstOrDefault() with capturing lambda (allocated per cell) with indexed for loop, avoiding delegate allocation on each of 28-42 cells per render frame. 3. ChartSeries DataLabelSettings — Add missing unsubscribe before resubscribe on LabelStyle.PropertyChanged, preventing duplicate handler accumulation and potential memory leak when LabelStyle is reassigned multiple times. 4. PolarAreaSegment — Pre-allocate List<float> with calculated capacity in GenerateInteriorPoints/GenerateStrokePoints, avoiding repeated resizing during each render frame. 5. SfTimePicker — Replace LINQ Select(int.Parse).Contains() pattern with simple for loop using int.TryParse, eliminating iterator allocation and intermediate sequence materialization during column selection changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Root Cause of the Issue
Multiple controls perform unnecessary memory allocations and redundant work in frequently-called paths:
Description of Change
Five targeted performance improvements across 5 files:
CartesianAxisLayout.cs —
GetAxisByName()used a LINQ query expression with.ToList()just to get the first matching axis. Replaced with aforeachloop that returns on first match, eliminating the list allocation entirely.Calendar MonthView.cs —
_specialDates.FirstOrDefault(details => ...)was called once per calendar cell (28-42 times per render frame), each time allocating a new delegate that captures the changingdateTimelocal. Extracted to aGetSpecialDateIcon()method using an indexedforloop.ChartSeries.cs —
DataLabelSettings_PropertyChangedsubscribed toLabelStyle.PropertyChangedwithout first unsubscribing, causing duplicate handlers to accumulate each timeLabelStylewas reassigned. Added the missing-=before+=.PolarAreaSegment.cs —
GenerateInteriorPoints()andGenerateStrokePoints()creatednew List<float>()with default capacity (called every render frame). Pre-allocated with calculated capacity(_pointsCount + 2) * 2to avoid repeated array resizing.SfTimePicker.cs —
.Select(m => int.Parse(m)).Contains(value)allocates an iterator, a delegate, and evaluates lazily. Replaced with a staticContainsParsedValue()helper using aforloop withint.TryParse— zero allocations.Issues Fixed
Performance optimization — no specific issue number.
Screenshots
N/A — internal allocation/performance changes with no visual impact.