From 14b677d01b51c955473c04a5e716db4a0984d42e Mon Sep 17 00:00:00 2001 From: Paul Anderson Date: Tue, 26 May 2026 09:03:11 +0530 Subject: [PATCH 1/2] Perf: Use direct index access instead of LINQ Min/Max on sorted array in BoxAndWhiskerSeries In CreateSegments(), after Array.Sort(yList), the Min() and Max() LINQ calls perform redundant O(n) iterations. Since the array is already sorted, we can use yList[0] and yList[^1] for O(1) access. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- maui/src/Charts/Series/BoxAndWhiskerSeries.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/maui/src/Charts/Series/BoxAndWhiskerSeries.cs b/maui/src/Charts/Series/BoxAndWhiskerSeries.cs index ad2fbfbf..043eed78 100644 --- a/maui/src/Charts/Series/BoxAndWhiskerSeries.cs +++ b/maui/src/Charts/Series/BoxAndWhiskerSeries.cs @@ -1086,8 +1086,9 @@ internal override void GenerateSegments(SeriesView seriesView) } else { - minimum = yList.Min(); - maximum = yList.Max(); + // yList is already sorted, so use direct index access instead of LINQ Min/Max. + minimum = yList[0]; + maximum = yList[^1]; } double actualMinimum = minimum; From f889217a1e00fb89352b3433988abd441771c7aa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 26 May 2026 09:49:09 +0000 Subject: [PATCH 2/2] Clarify BoxAndWhiskerSeries sorted yList assumption Agent-Logs-Url: https://github.com/syncfusion/maui-toolkit/sessions/deb0ed97-498d-47eb-90c1-f8c8805a10fd Co-authored-by: PaulAndersonS <42271912+PaulAndersonS@users.noreply.github.com> --- maui/src/Charts/Series/BoxAndWhiskerSeries.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maui/src/Charts/Series/BoxAndWhiskerSeries.cs b/maui/src/Charts/Series/BoxAndWhiskerSeries.cs index 043eed78..de7c059d 100644 --- a/maui/src/Charts/Series/BoxAndWhiskerSeries.cs +++ b/maui/src/Charts/Series/BoxAndWhiskerSeries.cs @@ -1040,6 +1040,7 @@ internal override void GenerateSegments(SeriesView seriesView) if (yList.Length > 0) { + // The quartile, whisker, and min/max calculations below all rely on ascending values. Array.Sort(yList); average = yList.Average(); } @@ -1086,7 +1087,7 @@ internal override void GenerateSegments(SeriesView seriesView) } else { - // yList is already sorted, so use direct index access instead of LINQ Min/Max. + // yList was sorted above and is not modified afterwards, so first/last entries are the min/max. minimum = yList[0]; maximum = yList[^1]; }