diff --git a/src/Benchmarks/Benchmarks/Query/QueryEntityComparisonBenchmark.cs b/src/Benchmarks/Benchmarks/Query/QueryEntityComparisonBenchmark.cs index c12373c8..0973d0d4 100644 --- a/src/Benchmarks/Benchmarks/Query/QueryEntityComparisonBenchmark.cs +++ b/src/Benchmarks/Benchmarks/Query/QueryEntityComparisonBenchmark.cs @@ -51,6 +51,9 @@ public QueryEntityComparisonBenchmark() }); } + [GlobalSetup(Target = nameof(EfficientDynamoDbFromInterfaceBenchmark))] + public void SetupMixedFromInterfaceBenchmark() => SetupBenchmark(x => EntitiesFactory.CreateMixedEntityFromInterface(x).ToDocument()); + [GlobalSetup] public void SetupMixedBenchmark() => SetupBenchmark(x => EntitiesFactory.CreateMixedEntity(x).ToDocument()); @@ -64,6 +67,16 @@ public async Task EfficientDynamoDbBenchmark() return result.Count; } + [Benchmark(Description = "EfficientDynamoDb-FromInterface")] + public async Task EfficientDynamoDbFromInterfaceBenchmark() + { + var result = await _efficientDbContext.Query() + .WithKeyExpression(Condition.On(x => x.Pk).EqualTo("test")) + .ToListAsync().ConfigureAwait(false); + + return result.Count; + } + [Benchmark(Description = "aws-sdk-net")] public async Task AwsSdkNetBenchmark() { diff --git a/src/Benchmarks/Entities/MixedEntityFromInterface.cs b/src/Benchmarks/Entities/MixedEntityFromInterface.cs new file mode 100644 index 00000000..0a6173a3 --- /dev/null +++ b/src/Benchmarks/Entities/MixedEntityFromInterface.cs @@ -0,0 +1,66 @@ +using System.Collections.Generic; +using Amazon.DynamoDBv2.DataModel; + +namespace Benchmarks.Entities +{ + public interface IMixedEntityFromInterface + { + [EfficientDynamoDb.Attributes.DynamoDbProperty("m")] + MapObject M { get; set; } + + [EfficientDynamoDb.Attributes.DynamoDbProperty("l1")] + List L1 { get; set; } + + [EfficientDynamoDb.Attributes.DynamoDbProperty("l2")] + List L2 { get; set; } + + [EfficientDynamoDb.Attributes.DynamoDbProperty("l3")] + List L3 { get; set; } + + [EfficientDynamoDb.Attributes.DynamoDbProperty("ss")] + HashSet Ss { get; set; } + + [EfficientDynamoDb.Attributes.DynamoDbProperty("ns")] + HashSet Ns { get; set; } + + [EfficientDynamoDb.Attributes.DynamoDbProperty("s")] + string S { get; set; } + + [EfficientDynamoDb.Attributes.DynamoDbProperty("n")] + int N { get; set; } + + [EfficientDynamoDb.Attributes.DynamoDbProperty("b")] + bool B { get; set; } + + } + + public class MixedEntityFromInterface : KeysOnlyEntity, IMixedEntityFromInterface + { + [DynamoDBProperty("m")] + public MapObject M { get; set; } + + [DynamoDBProperty("l1")] + public List L1 { get; set; } + + [DynamoDBProperty("l2")] + public List L2 { get; set; } + + [DynamoDBProperty("l3")] + public List L3 { get; set; } + + [DynamoDBProperty("ss")] + public HashSet Ss { get; set; } + + [DynamoDBProperty("ns")] + public HashSet Ns { get; set; } + + [DynamoDBProperty("s")] + public string S { get; set; } + + [DynamoDBProperty("n")] + public int N { get; set; } + + [DynamoDBProperty("b")] + public bool B { get; set; } + } +} \ No newline at end of file diff --git a/src/Benchmarks/Mocks/EntitiesFactory.cs b/src/Benchmarks/Mocks/EntitiesFactory.cs index 0ae4d2cb..3999999c 100644 --- a/src/Benchmarks/Mocks/EntitiesFactory.cs +++ b/src/Benchmarks/Mocks/EntitiesFactory.cs @@ -78,6 +78,24 @@ public static MixedEntity CreateMixedEntity(int index) }; } + public static MixedEntityFromInterface CreateMixedEntityFromInterface(int index) + { + return new MixedEntityFromInterface + { + Pk = $"pk_{index:0000}", + Sk = $"sk_{index:0000}", + B = index % 2 == 0, + N = index, + S = $"test_{index:0000}", + Ns = new HashSet {index}, + Ss = new HashSet {$"test_set_{index:0000}"}, + M = new MapObject {P1 = $"test_p0_{index:0000}"}, + L1 = new List {new MapObject {P1 = $"test_p1_{index:0000}"}}, + L2 = new List {new MapObject {P1 = $"test_p2_{index:0000}"}}, + L3 = new List {new MapObject {P1 = $"test_p3_{index:0000}"}} + }; + } + public static LargeStringFieldsEntity CreateLargeStringEntity(int index) { return new LargeStringFieldsEntity diff --git a/src/EfficientDynamoDb/Internal/Metadata/DdbClassInfo.cs b/src/EfficientDynamoDb/Internal/Metadata/DdbClassInfo.cs index 425fb73a..752e5368 100644 --- a/src/EfficientDynamoDb/Internal/Metadata/DdbClassInfo.cs +++ b/src/EfficientDynamoDb/Internal/Metadata/DdbClassInfo.cs @@ -51,13 +51,18 @@ public DdbClassInfo(Type type, DynamoDbContextMetadata metadata, DdbConverter co ConverterBase = converter; ConverterType = converter.GetType(); ClassType = ConverterBase.ClassType; + var typeInterfaces = new Stack(type.GetInterfaces()); switch (ClassType) { case DdbClassType.Object: { - for (var currentType = type; currentType != null; currentType = currentType.BaseType) + for (var currentType = type; currentType != null || typeInterfaces.Count > 0; currentType = currentType?.BaseType) { + if (currentType?.BaseType == null && typeInterfaces.Count <= 0) + continue; + + currentType ??= typeInterfaces.Pop(); const BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public |