From a87dc37b8b87240445c66bc14763a31dce3eb215 Mon Sep 17 00:00:00 2001 From: Loretta Date: Thu, 5 Feb 2026 17:11:24 +0100 Subject: [PATCH] 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. --- ...ySerializer.BinarySerializeTypeMetadata.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/AyCode.Core/Serializers/Binaries/AcBinarySerializer.BinarySerializeTypeMetadata.cs b/AyCode.Core/Serializers/Binaries/AcBinarySerializer.BinarySerializeTypeMetadata.cs index ab10cbc..d9c5775 100644 --- a/AyCode.Core/Serializers/Binaries/AcBinarySerializer.BinarySerializeTypeMetadata.cs +++ b/AyCode.Core/Serializers/Binaries/AcBinarySerializer.BinarySerializeTypeMetadata.cs @@ -55,6 +55,34 @@ public static partial class AcBinarySerializer /// private int[]? _metadataPropertyHashes; + /// + /// Lazy-computed array of reference properties (complex types + strings). + /// Used by scan pass to quickly iterate only properties that need reference tracking. + /// + private BinaryPropertyAccessor[]? _referenceProperties; + + /// + /// Gets the array of reference properties (complex types + strings). + /// Computed lazily on first access. + /// + public BinaryPropertyAccessor[] ReferenceProperties + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _referenceProperties ??= ComputeReferenceProperties(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private BinaryPropertyAccessor[] ComputeReferenceProperties() + { + var list = new List(); + foreach (var prop in Properties) + { + if (prop.IsComplexType || prop.AccessorType == PropertyAccessorType.String) + list.Add(prop); + } + return list.ToArray(); + } + public int[] MetadataPropertyHashes { [MethodImpl(MethodImplOptions.AggressiveInlining)]