perf: Chart control performance improvements#378
Open
PaulAndersonS wants to merge 1 commit into
Open
Conversation
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 performance bottlenecks in the Chart control's hot paths causing unnecessary allocations and repeated enumeration during render cycles.
Description of Change
This PR implements 10 performance improvements targeting allocation reduction and LINQ elimination in frequently-called Chart control code paths:
Hoist
.ToList()outside loop inGetTotalWidth()—CartesianChartArea.cs:.Values.ToList()[i]was creating a new list on every iteration.Replace
GetType().Name.Contains()withispattern matching —CartesianChartArea.cs: String-based type checks inCalculateStackingValues()inner loop replaced with compile-time type checks (is StackingColumn100Series or StackingLine100Series or StackingArea100Series).Cache indexed X values in
GetXValues()—CartesianSeries.cs: LINQ.ToList()was creating a new list on every call. Now caches the computed index list and invalidates on data source changes.Replace
.Where().Sum()with singleforeachloop —CartesianChartArea.cs:GetYValue()static method no longer double-enumerates the collection.Remove
.Where().ToList()inResetVisibleSeries()—StackingSeriesBase.cs: Direct iteration with inline predicate instead of allocating a filtered list.Remove
.Where().ToList()inResetSBSSegments()—CartesianChartArea.cs: Direct iteration instead of allocating a filtered list just to set flags.Replace
.Any()with manual loop inUpdateStackingSeries()—CartesianChartArea.cs: Eliminates LINQ delegate allocation with early-exit foreach loop.Eliminate
Cast<object>().ToList()inResetDataPoint()—ChartSeriesPartial.cs: UsesIEnumerable.GetEnumerator().MoveNext()to check for data existence without allocating a full list copy.Pre-compute coordinates in zoom/pan selection rendering —
ChartZoomPanView.cs: Cache computed x/y coordinates outside if/else branches to avoid redundant ternary evaluations per axis; reuseaxisRectlocal foractualArrangeRectcomputation.Replace nested LINQ
.FirstOrDefault().Any()with foreach loops —CartesianChartArea.cs: SBS grouping lookup now uses nested foreach with early break instead of LINQ with reflection.Issues Fixed
N/A — Performance improvement (no functional changes)
Screenshots
N/A — Internal implementation optimization only