Optimizations in Chart control - #401
Merged
Merged
Conversation
1. Replace string-based double comparison with Math.Abs epsilon check (ChartDataUtils.cs) 2. Add direct type checks in ConvertToDouble to avoid redundant ToString() allocations (ChartUtils.cs) 3. Materialize OfType<CartesianSeries>() result to prevent repeated LINQ evaluation (CartesianChartArea.cs) 4. Remove unnecessary .ToList() on Dictionary.Values - use foreach directly (CartesianChartArea.cs) 5. Eliminate unnecessary list copies in DataPointSelectionBehavior.ResetMultiSelection 6. Eliminate unnecessary list copies in SeriesSelectionBehavior.ResetMultiSelection 7. Use HashSet for O(1) lookups in trackball point filtering (ChartTrackballBehavior.cs) 8. Replace Cast<T>() LINQ wrapper with direct iteration in rendering loops (CircularSeries, FinancialSeriesBase, StepAreaSeries, AreaSeries, ScatterSeries, RangeAreaSeries) 9. Remove unnecessary .ToList() materialization in CartesianSeries.UpdateSbsSeries 10. Replace separate Min()/Max() LINQ calls with single-pass loop (BoxAndWhiskerSeries) These changes reduce memory allocations, eliminate redundant LINQ evaluations, and improve CPU efficiency in hot rendering and interaction paths. Co-authored-by: Copilot App <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.
Summary
This PR consolidates 10 performance improvements across the Chart control to reduce memory allocations, eliminate redundant LINQ evaluations, and improve CPU efficiency in hot rendering and interaction paths.
Performance Improvements
Math.Absepsilon checkConvertToDoubleto avoid redundantToString()OfType<CartesianSeries>()to prevent repeated LINQ evaluation.ToList()onDictionary.ValuesDataPointSelectionBehavior.ResetMultiSelectionSeriesSelectionBehavior.ResetMultiSelectionHashSetfor O(1) lookups in trackball point filteringCast<T>()LINQ wrapper with direct iteration.ToList()materializationMin()/Max()LINQ calls with single-pass loopBuild Verification
dotnet buildpasses with 0 errors