Enable AcBinary serialization for all test models

- Set `[AcBinarySerializable(true)]` on all SharedTestModels types
- Default `UseMetadata` to true for property hash footer
- Reset slotted ID maps and cache indices in serializer context
- Reduce test iterations for DEBUG builds to speed up runs
- Add debug comments in context `Clear()` method
This commit is contained in:
Loretta 2026-02-21 08:54:50 +01:00
parent cb2ee24a4c
commit fe35e60649
5 changed files with 30 additions and 25 deletions

View File

@ -46,8 +46,8 @@ public static class Program
private static readonly UTF8Encoding Utf8NoBom = new(encoderShouldEmitUTF8Identifier: false);
#if DEBUG
private static int WarmupIterations = 5;
private static int TestIterations = 10;
private static int WarmupIterations = 0;
private static int TestIterations = 1;
#else
private static int WarmupIterations = 5000;
private static int TestIterations = 1000;

View File

@ -55,7 +55,7 @@ public enum TestUserRole
/// Implements IId<int> for semantic $id/$ref serialization.
/// </summary>
[MemoryPackable]
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
[MessagePackObject]
public partial class SharedTag : IId<int>
{
@ -80,7 +80,7 @@ public partial class SharedTag : IId<int>
/// Shared category - for hierarchical cross-reference testing.
/// </summary>
[MemoryPackable]
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
[MessagePackObject]
public partial class SharedCategory : IId<int>
{
@ -106,7 +106,7 @@ public partial class SharedCategory : IId<int>
/// Shared user reference - appears in many places to test $ref deduplication.
/// </summary>
[MemoryPackable]
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
[MessagePackObject]
public partial class SharedUser : IId<int>
{
@ -136,7 +136,7 @@ public partial class SharedUser : IId<int>
/// User preferences - non-IId nested object
/// </summary>
[MemoryPackable]
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
[MessagePackObject]
public partial class UserPreferences
{
@ -162,7 +162,7 @@ public partial class UserPreferences
/// Does NOT implement IId, so uses standard Newtonsoft reference tracking.
/// </summary>
[MemoryPackable]
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
[MessagePackObject]
public partial class MetadataInfo
{
@ -190,7 +190,7 @@ public partial class MetadataInfo
/// Level 1: Main order - root of the hierarchy
/// </summary>
[MemoryPackable]
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
[MessagePackObject]
public partial class TestOrder : IId<int>
{
@ -250,7 +250,7 @@ public partial class TestOrder : IId<int>
/// Level 2: Order item with pallets
/// </summary>
[MemoryPackable]
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
[MessagePackObject]
public partial class TestOrderItem : IId<int>
{
@ -290,7 +290,7 @@ public partial class TestOrderItem : IId<int>
/// Level 3: Pallet containing measurements
/// </summary>
[MemoryPackable]
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
[MessagePackObject]
public partial class TestPallet : IId<int>
{
@ -333,7 +333,7 @@ public partial class TestPallet : IId<int>
/// Level 4: Measurement with multiple points
/// </summary>
[MemoryPackable]
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
[MessagePackObject]
public partial class TestMeasurement : IId<int>
{
@ -368,7 +368,7 @@ public partial class TestMeasurement : IId<int>
/// Level 5: Deepest level - measurement point
/// </summary>
[MemoryPackable]
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
[MessagePackObject]
public partial class TestMeasurementPoint : IId<int>
{
@ -402,7 +402,7 @@ public partial class TestMeasurementPoint : IId<int>
/// <summary>
/// Order with Guid Id - for testing Guid-based IId
/// </summary>
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public class TestGuidOrder : IId<Guid>
{
public Guid Id { get; set; }
@ -414,7 +414,7 @@ public class TestGuidOrder : IId<Guid>
/// <summary>
/// Item with Guid Id
/// </summary>
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public class TestGuidItem : IId<Guid>
{
public Guid Id { get; set; }
@ -430,7 +430,7 @@ public class TestGuidItem : IId<Guid>
/// Simulates NopCommerce GenericAttribute - stores key-value pairs where DateTime values
/// are stored as strings in the database.
/// </summary>
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public class TestGenericAttribute
{
public int Id { get; set; }
@ -442,7 +442,7 @@ public class TestGenericAttribute
/// DTO with GenericAttributes collection - simulates OrderDto with string-stored DateTime values.
/// This reproduces the production bug where Binary serialization was thought to corrupt DateTime strings.
/// </summary>
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public class TestDtoWithGenericAttributes : IId<int>
{
public int Id { get; set; }
@ -453,7 +453,7 @@ public class TestDtoWithGenericAttributes : IId<int>
/// <summary>
/// Order with nullable collections for null vs empty testing
/// </summary>
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public class TestOrderWithNullableCollections
{
public int Id { get; set; }
@ -466,7 +466,7 @@ public class TestOrderWithNullableCollections
/// Class with all primitive types for WASM/serialization testing
/// </summary>
[MemoryPackable]
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public partial class PrimitiveTestClass
{
public int IntValue { get; set; }
@ -489,7 +489,7 @@ public partial class PrimitiveTestClass
/// Class with extended primitive types for full serializer coverage.
/// Includes DateTimeOffset, TimeSpan, Dictionary, null properties.
/// </summary>
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public class ExtendedPrimitiveTestClass
{
public int Id { get; set; }
@ -519,7 +519,7 @@ public class ExtendedPrimitiveTestClass
/// <summary>
/// Class with array of objects containing null items for WriteNull coverage
/// </summary>
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public class ObjectWithNullItems
{
public int Id { get; set; }
@ -534,7 +534,7 @@ public class ObjectWithNullItems
/// "Server-side" DTO with extra properties that the "client" doesn't know about.
/// Used to test SkipValue functionality when deserializing unknown properties.
/// </summary>
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public class ServerCustomerDto : IId<int>
{
public int Id { get; set; }
@ -567,7 +567,7 @@ public class ServerCustomerDto : IId<int>
/// the deserializer must skip unknown properties correctly
/// while still maintaining string intern table consistency.
/// </summary>
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public class ClientCustomerDto : IId<int>
{
public int Id { get; set; }
@ -581,7 +581,7 @@ public class ClientCustomerDto : IId<int>
/// Server DTO with nested objects that client doesn't know about.
/// Tests skipping complex nested structures.
/// </summary>
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public class ServerOrderWithExtras : IId<int>
{
public int Id { get; set; }
@ -602,7 +602,7 @@ public class ServerOrderWithExtras : IId<int>
/// <summary>
/// Client version of the order - doesn't have Customer/RelatedCustomers properties.
/// </summary>
[AcBinarySerializable(false)]
[AcBinarySerializable(true)]
public class ClientOrderSimple : IId<int>
{
public int Id { get; set; }

View File

@ -115,6 +115,9 @@ public abstract class AcSerializerContextBase<TMetadata, TOptions>
/// </summary>
public virtual void Clear()
{
//System.Diagnostics.Debug.WriteLine($"Wrappers count: {_wrappers.Count}");
//Console.WriteLine($"Wrappers count: {_wrappers.Count}");
foreach (var wrapper in _wrappers.Values)
{
wrapper.ResetTracking(Options.UseAsync);

View File

@ -289,9 +289,11 @@ public static partial class AcBinarySerializer
_stringInternMap?.Reset();
_metadataSeenBits.AsSpan().Clear();
_metadataSeenOverflow?.Clear();
ResetSlottedMaps(_slottedIdMapsInt32);
ResetSlottedMaps(_slottedIdMapsInt64);
ResetSlottedMaps(_slottedIdMapsGuid);
_nextCacheIndex = 0;
NextFirstIndex = 0;
ScanVisitIndex = 0;

View File

@ -82,7 +82,7 @@ public sealed class AcBinarySerializerOptions : AcSerializerOptions
/// allowing the deserializer to match properties by name between different types.
/// Default: false (no overhead)
/// </summary>
public bool UseMetadata { get; set; } = false;
public bool UseMetadata { get; set; } = true;
public bool UseGeneratedCode { get; set; } = true;