Skip to content

perf: Chart control performance improvements#378

Merged
PaulAndersonS merged 3 commits into
mainfrom
paulandersons/perf-chart-control-improvements
Jun 11, 2026
Merged

perf: Chart control performance improvements#378
PaulAndersonS merged 3 commits 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>
@VimalaThirumalaikumar

Copy link
Copy Markdown

Tested and ensured, changes are fine

@SaiyathAliFathima SaiyathAliFathima left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are fine

@PaulAndersonS PaulAndersonS added this to the v1.0.11 milestone Jun 11, 2026
@PaulAndersonS PaulAndersonS merged commit dd9daeb into main Jun 11, 2026
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.

3 participants