Perf: Reduce allocations across 5 controls with targeted optimizations#377
Open
PaulAndersonS wants to merge 1 commit into
Open
Perf: Reduce allocations across 5 controls with targeted optimizations#377PaulAndersonS wants to merge 1 commit into
PaulAndersonS wants to merge 1 commit into
Conversation
1. OtpInput: Replace O(n²) Concat().ToArray() pattern with List-based collection building in AddEntry/SetInputFieldPosition/SetSeparatorPosition 2. Carousel (iOS): Replace .ToList().ForEach() with direct foreach loop, also cache IsInteractionEnable() result to avoid repeated calls 3. SfView: Remove redundant .AsReadOnly() wrapper in GetVisualChildren() 4. DatePicker: Replace .ToList().IndexOf() with Array.IndexOf() to avoid heap allocation when looking up month names 5. ProgressBar: Replace LINQ OrderBy().ToList() with List.Sort() for in-place sorting of gradient stops Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
MuniappanSubramanian
approved these changes
May 27, 2026
Collaborator
MuniappanSubramanian
left a comment
There was a problem hiding this comment.
Date Picker code changes are fine
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.
Root Cause of the Issue
Multiple controls allocate unnecessary collections (List, Array) in frequently-called methods, causing GC pressure and reducing throughput during layout, rendering, and user interaction.
Description of Change
Five targeted performance improvements that reduce heap allocations:
OtpInput (
SfOtpInput.cs) — Replaced O(n²)Concat(new[]{x}).ToArray()pattern inAddEntry,SetInputFieldPosition, andSetSeparatorPositionwith aList<T>-based approach that builds the collection once and converts to array at the end.Carousel iOS (
PlatformCarousel.iOS.cs) — Replaced.ToList().ForEach(...)with a directforeachloop, eliminating a List allocation. Also cached theIsInteractionEnable()result to avoid calling it N+1 times.SfView (
SfView.cs) — Removed the redundant.AsReadOnly()wrapper inGetVisualChildren(), which allocated an extraReadOnlyCollection<T>on every call.List<T>already implementsIReadOnlyList<T>.DatePicker (
SfDatePicker.cs,DatePickerHelper.cs) — ReplacedMonthNames.ToList().IndexOf(...)withArray.IndexOf(MonthNames, ...), eliminating 4 separate List allocations per month-selection event.ProgressBar (
SfLinearProgressBar.cs,SfCircularProgressBar.cs) — Replaced LINQOrderBy(...).ToList()withnew List<T>(source)+List.Sort()for in-place sorting of gradient stops, eliminating the intermediate iterator and sort buffer allocations.Issues Fixed
N/A — proactive performance improvement
Unit Tests Added
DatePickerMonthIndexUnitTests— VerifiesArray.IndexOfproduces identical results to the previousList.IndexOfapproach for all month name formatsLinearProgressBarGradientSortUnitTests— Verifies gradient stops are correctly handled after the sort optimization (out-of-order, single-stop, already-sorted scenarios)