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:
parent
cb2ee24a4c
commit
fe35e60649
|
|
@ -46,8 +46,8 @@ public static class Program
|
||||||
private static readonly UTF8Encoding Utf8NoBom = new(encoderShouldEmitUTF8Identifier: false);
|
private static readonly UTF8Encoding Utf8NoBom = new(encoderShouldEmitUTF8Identifier: false);
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
private static int WarmupIterations = 5;
|
private static int WarmupIterations = 0;
|
||||||
private static int TestIterations = 10;
|
private static int TestIterations = 1;
|
||||||
#else
|
#else
|
||||||
private static int WarmupIterations = 5000;
|
private static int WarmupIterations = 5000;
|
||||||
private static int TestIterations = 1000;
|
private static int TestIterations = 1000;
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ public enum TestUserRole
|
||||||
/// Implements IId<int> for semantic $id/$ref serialization.
|
/// Implements IId<int> for semantic $id/$ref serialization.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
[MessagePackObject]
|
[MessagePackObject]
|
||||||
public partial class SharedTag : IId<int>
|
public partial class SharedTag : IId<int>
|
||||||
{
|
{
|
||||||
|
|
@ -80,7 +80,7 @@ public partial class SharedTag : IId<int>
|
||||||
/// Shared category - for hierarchical cross-reference testing.
|
/// Shared category - for hierarchical cross-reference testing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
[MessagePackObject]
|
[MessagePackObject]
|
||||||
public partial class SharedCategory : IId<int>
|
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.
|
/// Shared user reference - appears in many places to test $ref deduplication.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
[MessagePackObject]
|
[MessagePackObject]
|
||||||
public partial class SharedUser : IId<int>
|
public partial class SharedUser : IId<int>
|
||||||
{
|
{
|
||||||
|
|
@ -136,7 +136,7 @@ public partial class SharedUser : IId<int>
|
||||||
/// User preferences - non-IId nested object
|
/// User preferences - non-IId nested object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
[MessagePackObject]
|
[MessagePackObject]
|
||||||
public partial class UserPreferences
|
public partial class UserPreferences
|
||||||
{
|
{
|
||||||
|
|
@ -162,7 +162,7 @@ public partial class UserPreferences
|
||||||
/// Does NOT implement IId, so uses standard Newtonsoft reference tracking.
|
/// Does NOT implement IId, so uses standard Newtonsoft reference tracking.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
[MessagePackObject]
|
[MessagePackObject]
|
||||||
public partial class MetadataInfo
|
public partial class MetadataInfo
|
||||||
{
|
{
|
||||||
|
|
@ -190,7 +190,7 @@ public partial class MetadataInfo
|
||||||
/// Level 1: Main order - root of the hierarchy
|
/// Level 1: Main order - root of the hierarchy
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
[MessagePackObject]
|
[MessagePackObject]
|
||||||
public partial class TestOrder : IId<int>
|
public partial class TestOrder : IId<int>
|
||||||
{
|
{
|
||||||
|
|
@ -250,7 +250,7 @@ public partial class TestOrder : IId<int>
|
||||||
/// Level 2: Order item with pallets
|
/// Level 2: Order item with pallets
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
[MessagePackObject]
|
[MessagePackObject]
|
||||||
public partial class TestOrderItem : IId<int>
|
public partial class TestOrderItem : IId<int>
|
||||||
{
|
{
|
||||||
|
|
@ -290,7 +290,7 @@ public partial class TestOrderItem : IId<int>
|
||||||
/// Level 3: Pallet containing measurements
|
/// Level 3: Pallet containing measurements
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
[MessagePackObject]
|
[MessagePackObject]
|
||||||
public partial class TestPallet : IId<int>
|
public partial class TestPallet : IId<int>
|
||||||
{
|
{
|
||||||
|
|
@ -333,7 +333,7 @@ public partial class TestPallet : IId<int>
|
||||||
/// Level 4: Measurement with multiple points
|
/// Level 4: Measurement with multiple points
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
[MessagePackObject]
|
[MessagePackObject]
|
||||||
public partial class TestMeasurement : IId<int>
|
public partial class TestMeasurement : IId<int>
|
||||||
{
|
{
|
||||||
|
|
@ -368,7 +368,7 @@ public partial class TestMeasurement : IId<int>
|
||||||
/// Level 5: Deepest level - measurement point
|
/// Level 5: Deepest level - measurement point
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
[MessagePackObject]
|
[MessagePackObject]
|
||||||
public partial class TestMeasurementPoint : IId<int>
|
public partial class TestMeasurementPoint : IId<int>
|
||||||
{
|
{
|
||||||
|
|
@ -402,7 +402,7 @@ public partial class TestMeasurementPoint : IId<int>
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Order with Guid Id - for testing Guid-based IId
|
/// Order with Guid Id - for testing Guid-based IId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public class TestGuidOrder : IId<Guid>
|
public class TestGuidOrder : IId<Guid>
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
|
@ -414,7 +414,7 @@ public class TestGuidOrder : IId<Guid>
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Item with Guid Id
|
/// Item with Guid Id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public class TestGuidItem : IId<Guid>
|
public class TestGuidItem : IId<Guid>
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
|
@ -430,7 +430,7 @@ public class TestGuidItem : IId<Guid>
|
||||||
/// Simulates NopCommerce GenericAttribute - stores key-value pairs where DateTime values
|
/// Simulates NopCommerce GenericAttribute - stores key-value pairs where DateTime values
|
||||||
/// are stored as strings in the database.
|
/// are stored as strings in the database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public class TestGenericAttribute
|
public class TestGenericAttribute
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
@ -442,7 +442,7 @@ public class TestGenericAttribute
|
||||||
/// DTO with GenericAttributes collection - simulates OrderDto with string-stored DateTime values.
|
/// 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.
|
/// This reproduces the production bug where Binary serialization was thought to corrupt DateTime strings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public class TestDtoWithGenericAttributes : IId<int>
|
public class TestDtoWithGenericAttributes : IId<int>
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
@ -453,7 +453,7 @@ public class TestDtoWithGenericAttributes : IId<int>
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Order with nullable collections for null vs empty testing
|
/// Order with nullable collections for null vs empty testing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public class TestOrderWithNullableCollections
|
public class TestOrderWithNullableCollections
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
@ -466,7 +466,7 @@ public class TestOrderWithNullableCollections
|
||||||
/// Class with all primitive types for WASM/serialization testing
|
/// Class with all primitive types for WASM/serialization testing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public partial class PrimitiveTestClass
|
public partial class PrimitiveTestClass
|
||||||
{
|
{
|
||||||
public int IntValue { get; set; }
|
public int IntValue { get; set; }
|
||||||
|
|
@ -489,7 +489,7 @@ public partial class PrimitiveTestClass
|
||||||
/// Class with extended primitive types for full serializer coverage.
|
/// Class with extended primitive types for full serializer coverage.
|
||||||
/// Includes DateTimeOffset, TimeSpan, Dictionary, null properties.
|
/// Includes DateTimeOffset, TimeSpan, Dictionary, null properties.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public class ExtendedPrimitiveTestClass
|
public class ExtendedPrimitiveTestClass
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
@ -519,7 +519,7 @@ public class ExtendedPrimitiveTestClass
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class with array of objects containing null items for WriteNull coverage
|
/// Class with array of objects containing null items for WriteNull coverage
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public class ObjectWithNullItems
|
public class ObjectWithNullItems
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
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.
|
/// "Server-side" DTO with extra properties that the "client" doesn't know about.
|
||||||
/// Used to test SkipValue functionality when deserializing unknown properties.
|
/// Used to test SkipValue functionality when deserializing unknown properties.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public class ServerCustomerDto : IId<int>
|
public class ServerCustomerDto : IId<int>
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
@ -567,7 +567,7 @@ public class ServerCustomerDto : IId<int>
|
||||||
/// the deserializer must skip unknown properties correctly
|
/// the deserializer must skip unknown properties correctly
|
||||||
/// while still maintaining string intern table consistency.
|
/// while still maintaining string intern table consistency.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public class ClientCustomerDto : IId<int>
|
public class ClientCustomerDto : IId<int>
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
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.
|
/// Server DTO with nested objects that client doesn't know about.
|
||||||
/// Tests skipping complex nested structures.
|
/// Tests skipping complex nested structures.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public class ServerOrderWithExtras : IId<int>
|
public class ServerOrderWithExtras : IId<int>
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
@ -602,7 +602,7 @@ public class ServerOrderWithExtras : IId<int>
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Client version of the order - doesn't have Customer/RelatedCustomers properties.
|
/// Client version of the order - doesn't have Customer/RelatedCustomers properties.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AcBinarySerializable(false)]
|
[AcBinarySerializable(true)]
|
||||||
public class ClientOrderSimple : IId<int>
|
public class ClientOrderSimple : IId<int>
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,9 @@ public abstract class AcSerializerContextBase<TMetadata, TOptions>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Clear()
|
public virtual void Clear()
|
||||||
{
|
{
|
||||||
|
//System.Diagnostics.Debug.WriteLine($"Wrappers count: {_wrappers.Count}");
|
||||||
|
//Console.WriteLine($"Wrappers count: {_wrappers.Count}");
|
||||||
|
|
||||||
foreach (var wrapper in _wrappers.Values)
|
foreach (var wrapper in _wrappers.Values)
|
||||||
{
|
{
|
||||||
wrapper.ResetTracking(Options.UseAsync);
|
wrapper.ResetTracking(Options.UseAsync);
|
||||||
|
|
|
||||||
|
|
@ -289,9 +289,11 @@ public static partial class AcBinarySerializer
|
||||||
_stringInternMap?.Reset();
|
_stringInternMap?.Reset();
|
||||||
_metadataSeenBits.AsSpan().Clear();
|
_metadataSeenBits.AsSpan().Clear();
|
||||||
_metadataSeenOverflow?.Clear();
|
_metadataSeenOverflow?.Clear();
|
||||||
|
|
||||||
ResetSlottedMaps(_slottedIdMapsInt32);
|
ResetSlottedMaps(_slottedIdMapsInt32);
|
||||||
ResetSlottedMaps(_slottedIdMapsInt64);
|
ResetSlottedMaps(_slottedIdMapsInt64);
|
||||||
ResetSlottedMaps(_slottedIdMapsGuid);
|
ResetSlottedMaps(_slottedIdMapsGuid);
|
||||||
|
|
||||||
_nextCacheIndex = 0;
|
_nextCacheIndex = 0;
|
||||||
NextFirstIndex = 0;
|
NextFirstIndex = 0;
|
||||||
ScanVisitIndex = 0;
|
ScanVisitIndex = 0;
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ public sealed class AcBinarySerializerOptions : AcSerializerOptions
|
||||||
/// allowing the deserializer to match properties by name between different types.
|
/// allowing the deserializer to match properties by name between different types.
|
||||||
/// Default: false (no overhead)
|
/// Default: false (no overhead)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool UseMetadata { get; set; } = false;
|
public bool UseMetadata { get; set; } = true;
|
||||||
|
|
||||||
public bool UseGeneratedCode { get; set; } = true;
|
public bool UseGeneratedCode { get; set; } = true;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue