perf: Improve Chart control rendering and data processing performance#388
Open
PaulAndersonS wants to merge 1 commit into
Open
perf: Improve Chart control rendering and data processing performance#388PaulAndersonS wants to merge 1 commit into
PaulAndersonS wants to merge 1 commit into
Conversation
- Replace string concatenation in loop with StringBuilder (CategoryAxis.cs) - Cache Dictionary.Values.ToList() before loop iteration (CartesianChartArea.cs) - Replace LINQ .ToList() index generation with pre-allocated for loops (CartesianSeries.cs) - Replace string concatenation in tooltip with string interpolation (BoxAndWhiskerSeries.cs) - Remove unnecessary .ToList() allocation in side-by-side series filtering (CartesianSeries.cs) - Replace List.Contains() with HashSet for O(1) lookups in GroupData (CategoryAxis.cs) - Eliminate Distinct().ToList() by maintaining uniqueness via HashSet (CategoryAxis.cs) - Dispose PathF before reallocation to reduce GC pressure (AreaSegment.cs) - Pre-allocate list capacity using ICollection.Count for ItemsSource (ChartSeriesPartial.cs) - Cache Math.Abs() results in trackball hit detection loop (CartesianSeries.cs) Co-authored-by: Copilot <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 delivers 10 performance improvements across the Chart control's hot paths, reducing GC pressure, memory allocations, and CPU usage during rendering and data processing.
Changes
Allocation Reduction
SideBySideSeriesPosition.Values.ToList()before loops — Avoids repeated list materialization per iteration inCartesianChartArea.csList<double>and for loops — Eliminates closure allocations and unnecessary enumerator overhead inCartesianSeries.csPolarSeries.cs— Consistent fix for the polar chart variant.ToList()from.Where()inUpdateSbsSeries— Iterates directly without intermediate list allocation.Where().ToList()inResetVisibleSeries— Inline filtering avoids allocation inStackingSeriesBase.csChartSeriesPartial.cs— UsesICollection.Countto set initial capacityString/StringBuilder Optimizations
StringBuilderfor label content assembly — Replaces repeated string concatenation inCategoryAxis.GetLabelContentBoxAndWhiskerSeries.csAlgorithm Improvements
HashSetfor O(1) deduplication inGroupData— Replaces O(n)List.Contains()calls, reducing axis grouping from O(n²) to O(n) inCategoryAxis.csMath.Absresults in trackball hit detection — Avoids redundant computation per iteration inCartesianSeries.csResource Management
PathFbefore reallocation inAreaSegment.csto reduce GC pressure from orphaned graphics objectsVerification