Skip to content

Eliminate reflection overhead and optimize string operations#6

Merged
FaysilAlshareef merged 4 commits into
mainfrom
copilot/fix-performance-issues-again
Feb 13, 2026
Merged

Eliminate reflection overhead and optimize string operations#6
FaysilAlshareef merged 4 commits into
mainfrom
copilot/fix-performance-issues-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 13, 2026

Performance profiling revealed critical bottlenecks in reflection-heavy aggregation operations and string manipulation.

Changes

  • Compiled property accessors: Replaced repeated PropertyInfo.GetValue() calls with cached compiled expression trees. Eliminates 40+ reflection invocations per aggregation operation.
private static readonly ConcurrentDictionary<PropertyInfo, Func<object, object>> _propertyAccessorCache = new();

private static Func<object, object> GetPropertyAccessor(PropertyInfo property)
{
    return _propertyAccessorCache.GetOrAdd(property, prop =>
    {
        var parameter = Expression.Parameter(typeof(object), "obj");
        var cast = Expression.Convert(parameter, prop.DeclaringType!);
        var propertyAccess = Expression.Property(cast, prop);
        var convertToObject = Expression.Convert(propertyAccess, typeof(object));
        return Expression.Lambda<Func<object, object>>(convertToObject, parameter).Compile();
    });
}
  • Property metadata caching: Memoized Type.GetProperties() results in PropertyExtractor using ConcurrentDictionary<(Type, bool), PropertyInfo[]>.

  • Column letter generation: Replaced O(n²) string concatenation with char array and backward fill pattern.

  • Conditional formatting lookup: Dictionary-based property index lookup instead of O(n×m) Array.FindIndex in loop.

  • Formatter selection: Direct max-priority scan replaced OrderByDescending().FirstOrDefault() LINQ chain.

All caches use ConcurrentDictionary for thread-safe concurrent access patterns.

Original prompt

This section details on the original issue you should resolve

<issue_title>Scan for preformance issues and fix there</issue_title>
<issue_description>Scan for preformance issues and fix there </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 13, 2026 19:48
Co-authored-by: FaysilAlshareef <99669048+FaysilAlshareef@users.noreply.github.com>
…ColumnLetter

Co-authored-by: FaysilAlshareef <99669048+FaysilAlshareef@users.noreply.github.com>
Co-authored-by: FaysilAlshareef <99669048+FaysilAlshareef@users.noreply.github.com>
Copilot AI changed the title [WIP] Scan for performance issues and fix them Eliminate reflection overhead and optimize string operations Feb 13, 2026
@FaysilAlshareef FaysilAlshareef marked this pull request as ready for review February 13, 2026 19:56
@FaysilAlshareef FaysilAlshareef merged commit 51dfade into main Feb 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scan for preformance issues and fix there

2 participants