Add ReferenceProperties for efficient reference tracking

Introduce a lazily-computed ReferenceProperties array to AcBinarySerializer, containing only complex and string properties. This enables efficient iteration and reference tracking during serialization by filtering relevant properties on first access.
This commit is contained in:
Loretta 2026-02-05 17:11:24 +01:00
parent e8a0d36e43
commit a87dc37b8b
1 changed files with 28 additions and 0 deletions

View File

@ -55,6 +55,34 @@ public static partial class AcBinarySerializer
/// </summary> /// </summary>
private int[]? _metadataPropertyHashes; private int[]? _metadataPropertyHashes;
/// <summary>
/// Lazy-computed array of reference properties (complex types + strings).
/// Used by scan pass to quickly iterate only properties that need reference tracking.
/// </summary>
private BinaryPropertyAccessor[]? _referenceProperties;
/// <summary>
/// Gets the array of reference properties (complex types + strings).
/// Computed lazily on first access.
/// </summary>
public BinaryPropertyAccessor[] ReferenceProperties
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _referenceProperties ??= ComputeReferenceProperties();
}
[MethodImpl(MethodImplOptions.NoInlining)]
private BinaryPropertyAccessor[] ComputeReferenceProperties()
{
var list = new List<BinaryPropertyAccessor>();
foreach (var prop in Properties)
{
if (prop.IsComplexType || prop.AccessorType == PropertyAccessorType.String)
list.Add(prop);
}
return list.ToArray();
}
public int[] MetadataPropertyHashes public int[] MetadataPropertyHashes
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]