perf: Chart control performance improvements#379
Open
PaulAndersonS wants to merge 1 commit into
Open
Conversation
…ring - Cache SideBySideSeriesPosition.Values.ToList() outside loop in GetTotalWidth() - Replace LINQ Where().Sum() with for loop in GetYValue() - Replace Cast<FastLineSegment>() foreach with direct index for loops in FastLineSeries - Replace LINQ Where().OrderBy() with manual filter + List.Sort() in SmartLabelAlignment - Replace four LINQ Where().Min/Max() calls with single-pass for loops in ErrorBarSegment - Skip InvalidateMeasure when position value unchanged in DataLabelItemView - Reuse PreviousPointInfos list via Clear+AddRange instead of new allocation per move - Replace LINQ OrderBy with in-place List.Sort() in ValidateTrackballBehaviorForAllSeries - Replace Where().ToList() with in-place RemoveAll in HistogramSeries - Remove unnecessary ToList allocation in StackingSeriesBase.ResetVisibleSeries Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d94614b to
e41c059
Compare
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.
Chart Control Performance Improvements
This PR consolidates 10 performance optimizations targeting hot paths in the Chart control — rendering, layout, data processing, and user interaction.
Changes
Cache
.ToList()outside loop (CartesianChartArea.cs) — Avoids repeated List allocation on every loop iteration inGetTotalWidth()and SBS positioning.Replace LINQ
Where().Sum()with for loop (CartesianChartArea.cs) — Eliminates iterator allocations and delegate invocations inGetYValue().Replace
.Cast<FastLineSegment>()with indexed for loop (FastLineSeries.cs) — Removes type-checking enumerator overhead in 3 hot rendering/hit-testing methods.Replace LINQ
Where().OrderBy()with filter +List.Sort()(ChartTrackballBehavior.cs) — Eliminates intermediate array allocation and multi-pass enumeration during mouse tracking.Combine 4 LINQ
Where().Min/Max()into single-pass loop (ErrorBarSegment.cs) — Reduces 4 full enumerations to 2 single-pass loops for min/max calculation.Skip
InvalidateMeasurewhen value unchanged (DataLabelItemView.cs) — Prevents cascading layout invalidations when position is set to same value.Reuse
PreviousPointInfoslist (ChartTrackballBehavior.cs) — UsesClear()+AddRange()instead of allocating a new list on every mouse move.Replace LINQ
OrderBywith in-placeList.Sort()(ChartTrackballBehavior.cs) — Avoids array allocation from collection expression inValidateTrackballBehaviorForAllSeries.Replace
Where().ToList()withRemoveAll()(HistogramSeries.cs) — Filters NaN values in-place instead of creating a new list copy.Remove unnecessary
.ToList()allocation (StackingSeriesBase.cs) — Iterates visible series directly with inline check instead of creating intermediate filtered list.Impact