Skip to content

perf: Chart control performance improvements#399

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

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

Conversation

@PaulAndersonS

Copy link
Copy Markdown
Collaborator

Root Cause of the Issue

The Chart control source code uses several LINQ patterns (.Reverse(), .Cast<>(), .Where().ToList()) and repeated string operations that cause unnecessary heap allocations and repeated work on every frame/update cycle.

Description of Change

This PR implements 10 targeted performance improvements in the Chart control source code:

  1. Replace .Reverse() with reverse index loop in ChartBase.cs — avoids allocating a reversed collection during tooltip hit-testing
  2. Remove .Where().ToList() allocation in CartesianSeries.cs — replaces filtered list with direct iteration
  3. Replace .Cast<CartesianSeries>() with pattern matching in ChartAxis.cs — eliminates LINQ enumerator overhead
  4. Cache IndexOf calls in ChartSeriesPartial.cs — avoids scanning the same string multiple times
  5. Replace string concatenation with interpolation in ChartSeries.cs — minor allocation improvement
  6. Replace .Cast<CartesianSeries>() in group update in ChartSeriesPartial.cs — pattern matching loop
  7. Simplify ItemsSource IList check — already optimized in current code (no change needed)
  8. Cache .Count in loop conditions in CartesianAxisRenderer.cs — avoids repeated property access
  9. Cache complex property path check in ChartSeriesPartial.cs — introduces _isComplexXProperty field to avoid repeated String.Contains calls
  10. Replace remaining .Cast<>() usages in CartesianSeries.cs legend item loops — pattern matching with indexed access

Issues Fixed

N/A — Performance improvement

Screenshots

N/A — No visual changes

… caching

- Replace .Reverse() with reverse index loop in tooltip hit-testing
- Remove unnecessary .Where().ToList() allocations
- Replace .Cast<>() LINQ wrappers with pattern matching loops
- Cache repeated string IndexOf calls
- Replace string concatenation with interpolation
- Cache .Count in loop conditions
- Cache complex property path checks

Co-authored-by: Copilot App <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