Skip to content

perf: Chart control performance improvements#378

Open
PaulAndersonS wants to merge 1 commit into
mainfrom
paulandersons/perf-chart-control-improvements
Open

perf: Chart control performance improvements#378
PaulAndersonS wants to merge 1 commit into
mainfrom
paulandersons/perf-chart-control-improvements

Conversation

@PaulAndersonS
Copy link
Copy Markdown
Collaborator

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:

  1. Hoist .ToList() outside loop in GetTotalWidth()CartesianChartArea.cs: .Values.ToList()[i] was creating a new list on every iteration.

  2. Replace GetType().Name.Contains() with is pattern matchingCartesianChartArea.cs: String-based type checks in CalculateStackingValues() inner loop replaced with compile-time type checks (is StackingColumn100Series or StackingLine100Series or StackingArea100Series).

  3. 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.

  4. Replace .Where().Sum() with single foreach loopCartesianChartArea.cs: GetYValue() static method no longer double-enumerates the collection.

  5. Remove .Where().ToList() in ResetVisibleSeries()StackingSeriesBase.cs: Direct iteration with inline predicate instead of allocating a filtered list.

  6. Remove .Where().ToList() in ResetSBSSegments()CartesianChartArea.cs: Direct iteration instead of allocating a filtered list just to set flags.

  7. Replace .Any() with manual loop in UpdateStackingSeries()CartesianChartArea.cs: Eliminates LINQ delegate allocation with early-exit foreach loop.

  8. Eliminate Cast<object>().ToList() in ResetDataPoint()ChartSeriesPartial.cs: Uses IEnumerable.GetEnumerator().MoveNext() to check for data existence without allocating a full list copy.

  9. Pre-compute coordinates in zoom/pan selection renderingChartZoomPanView.cs: Cache computed x/y coordinates outside if/else branches to avoid redundant ternary evaluations per axis; reuse axisRect local for actualArrangeRect computation.

  10. Replace nested LINQ .FirstOrDefault().Any() with foreach loopsCartesianChartArea.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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant