Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Benchmarks/Benchmarks/Query/QueryEntityComparisonBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public QueryEntityComparisonBenchmark()
});
}

[GlobalSetup(Target = nameof(EfficientDynamoDbFromInterfaceBenchmark))]
public void SetupMixedFromInterfaceBenchmark() => SetupBenchmark<MixedEntityFromInterface>(x => EntitiesFactory.CreateMixedEntityFromInterface(x).ToDocument());

[GlobalSetup]
public void SetupMixedBenchmark() => SetupBenchmark<MixedEntity>(x => EntitiesFactory.CreateMixedEntity(x).ToDocument());

Expand All @@ -64,6 +67,16 @@ public async Task<int> EfficientDynamoDbBenchmark()
return result.Count;
}

[Benchmark(Description = "EfficientDynamoDb-FromInterface")]
public async Task<int> EfficientDynamoDbFromInterfaceBenchmark()
{
var result = await _efficientDbContext.Query<MixedEntityFromInterface>()
.WithKeyExpression(Condition<MixedEntityFromInterface>.On(x => x.Pk).EqualTo("test"))
.ToListAsync().ConfigureAwait(false);

return result.Count;
}

[Benchmark(Description = "aws-sdk-net")]
public async Task<int> AwsSdkNetBenchmark()
{
Expand Down
66 changes: 66 additions & 0 deletions src/Benchmarks/Entities/MixedEntityFromInterface.cs
Original file line number Diff line number Diff line change
@@ -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<MapObject> L1 { get; set; }

[EfficientDynamoDb.Attributes.DynamoDbProperty("l2")]
List<MapObject> L2 { get; set; }

[EfficientDynamoDb.Attributes.DynamoDbProperty("l3")]
List<MapObject> L3 { get; set; }

[EfficientDynamoDb.Attributes.DynamoDbProperty("ss")]
HashSet<string> Ss { get; set; }

[EfficientDynamoDb.Attributes.DynamoDbProperty("ns")]
HashSet<int> 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<MapObject> L1 { get; set; }

[DynamoDBProperty("l2")]
public List<MapObject> L2 { get; set; }

[DynamoDBProperty("l3")]
public List<MapObject> L3 { get; set; }

[DynamoDBProperty("ss")]
public HashSet<string> Ss { get; set; }

[DynamoDBProperty("ns")]
public HashSet<int> Ns { get; set; }

[DynamoDBProperty("s")]
public string S { get; set; }

[DynamoDBProperty("n")]
public int N { get; set; }

[DynamoDBProperty("b")]
public bool B { get; set; }
}
}
18 changes: 18 additions & 0 deletions src/Benchmarks/Mocks/EntitiesFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> {index},
Ss = new HashSet<string> {$"test_set_{index:0000}"},
M = new MapObject {P1 = $"test_p0_{index:0000}"},
L1 = new List<MapObject> {new MapObject {P1 = $"test_p1_{index:0000}"}},
L2 = new List<MapObject> {new MapObject {P1 = $"test_p2_{index:0000}"}},
L3 = new List<MapObject> {new MapObject {P1 = $"test_p3_{index:0000}"}}
};
}

public static LargeStringFieldsEntity CreateLargeStringEntity(int index)
{
return new LargeStringFieldsEntity
Expand Down
7 changes: 6 additions & 1 deletion src/EfficientDynamoDb/Internal/Metadata/DdbClassInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(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 |
Expand Down