Skip to content

feat: Implement caching for reflection lookups to optimize serialization performance#53

Merged
IvanMurzak merged 7 commits into
mainfrom
update/serialization-optimization
Jan 10, 2026
Merged

feat: Implement caching for reflection lookups to optimize serialization performance#53
IvanMurzak merged 7 commits into
mainfrom
update/serialization-optimization

Conversation

@IvanMurzak

@IvanMurzak IvanMurzak commented Jan 9, 2026

Copy link
Copy Markdown
Owner

This pull request introduces significant performance improvements across the reflection-based serialization and type utilities in the codebase by adding thread-safe caching for various expensive reflection operations. These changes reduce redundant reflection calls, especially during population, serialization, and type analysis, which is crucial for large object graphs or frequent access patterns.

Reflection and Serialization Caching

  • Added thread-safe caches for field and property lookup in BaseReflectionConverter<T> to avoid repeated reflection when populating objects from data; includes new methods GetCachedField, GetCachedProperty, and a cache for serializable member names used in error reporting.
  • Introduced static caches for serializable fields and properties in BaseReflectionConverter<T>, ensuring that repeated serialization operations are much faster by reusing reflection results. [1] [2] [3]

Registry and Converter Lookup Optimization

  • Implemented a cache for converter lookups in Reflector.Registry so that the best converter for a type is cached and reused; the cache is properly invalidated when converters are added or removed. [1] [2] [3] [4]

Type Utilities Performance

  • Added a cache for enumerable item type resolution in TypeUtils, dramatically reducing the cost of determining element types for collections; includes a method to clear this cache when needed. [1] [2] [3]

Error Reporting and Reflection Usage

  • Updated error reporting in population methods to use cached member names, reducing reflection overhead and improving performance when reporting missing fields or properties. [1] [2]

These changes collectively make the library much more efficient and scalable for reflection-heavy scenarios.

@IvanMurzak IvanMurzak self-assigned this Jan 9, 2026
@IvanMurzak IvanMurzak requested a review from Copilot January 9, 2026 17:59
@IvanMurzak IvanMurzak added the enhancement New feature or request label Jan 9, 2026
@github-actions

github-actions Bot commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

Test Results

    2 files      2 suites   7m 55s ⏱️
1 119 tests 1 119 ✅ 0 💤 0 ❌
2 238 runs  2 238 ✅ 0 💤 0 ❌

Results for commit 374f1a6.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements caching mechanisms for reflection lookups to optimize serialization performance. The caching is applied to multiple areas including type enumerable item type resolution, converter lookups, serializable fields/properties detection, and field/property metadata lookups.

  • Adds thread-safe caching using ConcurrentDictionary across multiple reflection-heavy operations
  • Implements cache invalidation strategy for converter lookups when registry changes
  • Provides new public APIs for cache management in TypeUtils

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
ReflectorNet/src/Utils/TypeUtils.cs Adds caching for enumerable item type lookups with a new ClearEnumerableItemTypeCache method
ReflectorNet/src/Reflector/Reflector.Registry.cs Implements converter lookup caching with automatic invalidation when converters are added/removed
ReflectorNet/src/Converter/Reflection/Base/BaseReflectionConverter.cs Adds static caches for serializable fields and properties to avoid repeated reflection calls
ReflectorNet/src/Converter/Reflection/Base/BaseReflectionConverter.Populate.cs Implements caching for field/property lookups and serializable member names used in error messages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ReflectorNet/src/Converter/Reflection/Base/BaseReflectionConverter.cs Outdated
Comment thread ReflectorNet/src/Converter/Reflection/Base/BaseReflectionConverter.Populate.cs Outdated
Comment thread ReflectorNet/src/Utils/TypeUtils.cs
Comment thread ReflectorNet/src/Converter/Reflection/Base/BaseReflectionConverter.Populate.cs Outdated
Comment thread ReflectorNet/src/Converter/Reflection/Base/BaseReflectionConverter.Populate.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 16 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ReflectorNet/src/Utils/TypeMemberUtils.cs Outdated
Comment thread ReflectorNet/src/Reflector/Reflector.Registry.cs
Comment thread ReflectorNet/src/Utils/TypeUtils.cs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 14 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ReflectorNet/src/Utils/TypeMemberUtils.cs
Comment thread ReflectorNet/src/Utils/TypeUtils.cs
Comment thread ReflectorNet/src/Utils/TypeMemberUtils.cs
Comment thread ReflectorNet/src/Utils/TypeUtils.cs Outdated
Comment thread ReflectorNet/src/Utils/TypeUtils.cs
Comment thread ReflectorNet/src/Utils/TypeUtils.cs Outdated
Comment thread ReflectorNet.Tests/src/Utils/LruCacheTests.cs
Comment thread ReflectorNet.Tests/src/Utils/LruCacheTests.cs Outdated
Comment thread ReflectorNet.Tests/src/Utils/LruCacheTests.cs Outdated
Comment thread ReflectorNet.Tests/src/Utils/LruCacheTests.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@IvanMurzak IvanMurzak merged commit 3ea90c1 into main Jan 10, 2026
2 checks passed
@IvanMurzak IvanMurzak deleted the update/serialization-optimization branch January 10, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants