Skip to content
Merged
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
84 changes: 84 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Benchmarker
TODO use this before merging
on:
push:
branches:
- main

permissions:
contents: write
deployments: write

jobs:
temporal:
name: Temporal Marshalling
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Run
run: dotnet run --project tests/DynamoDBGenerator.SourceGenerator.Benchmarks --configuration 'Release' -- --exporters 'JSON' --filter '*TemporalBenchmarks*' --memory --job 'Default'
- name: Store
uses: rhysd/github-action-benchmark@v1
with:
name: Temporal Marshalling
tool: 'benchmarkdotnet'
output-file-path: BenchmarkDotNet.Artifacts/results/DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.TemporalBenchmarks-report-full-compressed.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '200%'
benchmark-data-dir-path: 'benchmarks/marshalling/temporal'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@inputfalken'
primitve:
name: Primitive Marshalling
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Run
run: dotnet run --project tests/DynamoDBGenerator.SourceGenerator.Benchmarks --configuration 'Release' -- --exporters 'JSON' --filter '*PrimitiveBenchmarks*' --memory --job 'Default'
- name: Store
uses: rhysd/github-action-benchmark@v1
with:
name: Primitive Marshalling
tool: 'benchmarkdotnet'
output-file-path: BenchmarkDotNet.Artifacts/results/DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.PrimitiveBenchmarks-report-full-compressed.json
github-token: ${{ secrets.GITHUB_TOKEN }}
benchmark-data-dir-path: 'benchmarks/marshalling/primitive'
auto-push: true
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@inputfalken'
collection:
name: Collection Marshalling
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Run
run: dotnet run --project tests/DynamoDBGenerator.SourceGenerator.Benchmarks --configuration 'Release' -- --exporters 'JSON' --filter '*CollectionBenchmarks*' --memory --job 'Default'
- name: Store
uses: rhysd/github-action-benchmark@v1
with:
name: Collection Marshalling
tool: 'benchmarkdotnet'
output-file-path: BenchmarkDotNet.Artifacts/results/DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling.CollectionBenchmarks-report-full-compressed.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
benchmark-data-dir-path: 'benchmarks/marshalling/collection'
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@inputfalken'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks;

public sealed record Container<T>(T Value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Dtos;

//[SimpleJob(RuntimeMoniker.Net80)]
//[MemoryDiagnoser]
//public class PersonBenchmarker() : MarshalBenchmarker<PersonEntity>(
// PersonEntity.PersonEntityMarshaller.Marshall,
// PersonEntity.PersonEntityMarshaller.Unmarshall
//);
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Runtime.CompilerServices;
using Amazon.DynamoDBv2.Model;
using AutoFixture;

namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling;

public class DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4>
where T4 : IAttributeExpressionValueTracker<T2>
where T3 : IAttributeExpressionNameTracker
{
private readonly IDynamoDBMarshaller<T, T2, T3, T4> _marshaller;
private readonly T _element;
private readonly Dictionary<string, AttributeValue> _attributeValues;

public DynamoDbMarshallerBenchmarkHelper(IDynamoDBMarshaller<T, T2, T3, T4> marshaller)
{
_marshaller = marshaller;
_element = SetupFixture().Create<T>();
_attributeValues = marshaller.Marshall(_element);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Unmarshall() => _marshaller.Unmarshall(_attributeValues);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Dictionary<string, AttributeValue> Marshall() => _marshaller.Marshall(_element);

private static Fixture SetupFixture()
{
var fixture = new Fixture();
fixture.Customize<DateOnly>(o => o.FromFactory((DateTime dt) => DateOnly.FromDateTime(dt)));
fixture.Customize<TimeOnly>(o => o.FromFactory((DateTime dt) => TimeOnly.FromDateTime(dt)));
// Allow recursive types
fixture.Behaviors
.OfType<ThrowingRecursionBehavior>()
.ToList()
.ForEach(b => fixture.Behaviors.Remove(b));
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
return fixture;
}
}

public static class Extensions
{
public static DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4> ToBenchmarkHelper<T, T2, T3, T4>(
this IDynamoDBMarshaller<T, T2, T3, T4> marshaller) where T3 : IAttributeExpressionNameTracker
where T4 : IAttributeExpressionValueTracker<T2>
{
return new DynamoDbMarshallerBenchmarkHelper<T, T2, T3, T4>(marshaller);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Amazon.DynamoDBv2.Model;
using BenchmarkDotNet.Attributes;
using DynamoDBGenerator.Attributes;

namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling;

[DynamoDBMarshaller(EntityType = typeof(Container<Dictionary<string, int>>), AccessName = "DictionaryMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<HashSet<string>>), AccessName = "StringHashSetMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<List<string>>), AccessName = "ListMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<HashSet<int>>), AccessName = "IntHashSetMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<List<KeyValuePair<string, int>>>), AccessName = "KeyValuePairListMarshaller")]
public partial class CollectionBenchmarks
{
private readonly DynamoDbMarshallerBenchmarkHelper<Container<Dictionary<string, int>>, Container<Dictionary<string, int>>, ContainerDictionarystringintNames, ContainerDictionarystringintValues> _dictionary = DictionaryMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<HashSet<string>>, Container<HashSet<string>>, ContainerHashSetstringNames, ContainerHashSetstringValues> _stringHashSet = StringHashSetMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<List<string>>, Container<List<string>>, ContainerListstringNames, ContainerListstringValues> _stringList = ListMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<HashSet<int>>, Container<HashSet<int>>, ContainerHashSetintNames, ContainerHashSetintValues> _intHashSet = IntHashSetMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<List<KeyValuePair<string, int>>>, Container<List<KeyValuePair<string, int>>>, ContainerListKeyValuePairstringintNames, ContainerListKeyValuePairstringintValues> _keyValuePairList = KeyValuePairListMarshaller.ToBenchmarkHelper();

[Benchmark]
public Container<Dictionary<string, int>> Unmarshall_Dictionary() => _dictionary.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_Dictionary() => _dictionary.Marshall();

[Benchmark]
public Container<HashSet<string>> Unmarshall_StringHashSet() => _stringHashSet.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_StringHashSet() => _stringHashSet.Marshall();

[Benchmark]
public Container<List<string>> Unmarshall_StringList() => _stringList.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_StringList() => _stringList.Marshall();

[Benchmark]
public Container<HashSet<int>> Unmarshall_IntHashSet() => _intHashSet.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_IntHashSet() => _intHashSet.Marshall();

[Benchmark]
public Container<List<KeyValuePair<string,int>>> Unmarshall_KeyValuePairList() => _keyValuePairList.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_KeyValuePairList() => _keyValuePairList.Marshall();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using Amazon.DynamoDBv2.Model;
using BenchmarkDotNet.Attributes;
using DynamoDBGenerator.Attributes;

namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling;

[DynamoDBMarshaller(EntityType = typeof(Container<bool>), AccessName = "BooleanMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<char>), AccessName = "CharMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<int>), AccessName = "Int32Marshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<long>), AccessName = "Int64Marshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<string>), AccessName = "StringMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<uint>), AccessName = "UInt32Marshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<ulong>), AccessName = "UInt64Marshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<Guid>), AccessName = "GuidMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<DayOfWeek>), AccessName = "EnumMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<double>), AccessName = "DoubleMarshaller")]
public partial class PrimitiveBenchmarks
{
private readonly DynamoDbMarshallerBenchmarkHelper<Container<bool>, Container<bool>, ContainerboolNames, ContainerboolValues> _bool = BooleanMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<char>, Container<char>, ContainercharNames, ContainercharValues> _char = CharMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<int>, Container<int>, ContainerintNames, ContainerintValues> _int = Int32Marshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<long>, Container<long>, ContainerlongNames, ContainerlongValues> _long = Int64Marshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<string>, Container<string>, ContainerstringNames, ContainerstringValues> _string = StringMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<uint>, Container<uint>, ContaineruintNames, ContaineruintValues> _uint = UInt32Marshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<ulong>, Container<ulong>, ContainerulongNames, ContainerulongValues> _ulong = UInt64Marshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<Guid>, Container<Guid>, ContainerGuidNames, ContainerGuidValues> _guid = GuidMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<DayOfWeek>, Container<DayOfWeek>, ContainerDayOfWeekNames, ContainerDayOfWeekValues> _enum = EnumMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<double>, Container<double>, ContainerdoubleNames, ContainerdoubleValues> _double = DoubleMarshaller.ToBenchmarkHelper();

[Benchmark]
public Container<bool> Unmarshall_Bool() => _bool.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_Bool() => _bool.Marshall();

[Benchmark]
public Container<char> Unmarshall_Char() => _char.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_Char() => _char.Marshall();

[Benchmark]
public Container<int> Unmarshall_Int32() => _int.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_Int() => _int.Marshall();

[Benchmark]
public Container<long> Unmarshall_Int64() => _long.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_Int64() => _long.Marshall();

[Benchmark]
public Container<string> Unmarshall_String() => _string.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_String() => _string.Marshall();

[Benchmark]
public Container<uint> Unmarshall_UInt32() => _uint.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_UInt32() => _uint.Marshall();

[Benchmark]
public Container<ulong> Unmarshall_UInt64() => _ulong.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_Uint64() => _ulong.Marshall();

[Benchmark]
public Container<Guid> Unmarshall_Guid() => _guid.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_Guid() => _guid.Marshall();

[Benchmark]
public Container<DayOfWeek> Unmarshall_Enum() => _enum.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_Enum() => _enum.Marshall();

[Benchmark]
public Container<double> Unmarshall_Double() => _double.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_Double() => _double.Marshall();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Amazon.DynamoDBv2.Model;
using BenchmarkDotNet.Attributes;
using DynamoDBGenerator.Attributes;

namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks.Marshalling;

[DynamoDBMarshaller(EntityType = typeof(Container<DateTime>), AccessName = "DateTimeMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<DateTimeOffset>), AccessName = "DateTimeOffsetMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<DateOnly>), AccessName = "DateOnlyMarshaller")]
[DynamoDBMarshaller(EntityType = typeof(Container<TimeOnly>), AccessName = "TimeOnlyMarshaller")]
public partial class TemporalBenchmarks
{
private readonly DynamoDbMarshallerBenchmarkHelper<Container<DateTime>, Container<DateTime>, ContainerDateTimeNames, ContainerDateTimeValues> _dateTime = DateTimeMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<DateTimeOffset>, Container<DateTimeOffset>, ContainerDateTimeOffsetNames, ContainerDateTimeOffsetValues> _dateTimeOffset = DateTimeOffsetMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<DateOnly>, Container<DateOnly>, ContainerDateOnlyNames, ContainerDateOnlyValues> _dateOnly = DateOnlyMarshaller.ToBenchmarkHelper();
private readonly DynamoDbMarshallerBenchmarkHelper<Container<TimeOnly>, Container<TimeOnly>, ContainerTimeOnlyNames, ContainerTimeOnlyValues> _timeOnly = TimeOnlyMarshaller.ToBenchmarkHelper();

[Benchmark]
public Container<TimeOnly> Unmarshall_TimeOnly() => _timeOnly.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_TimeOnly() => _timeOnly.Marshall();

[Benchmark]
public Container<DateOnly> Unmarshall_DateOnly() => _dateOnly.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_DateOnly() => _dateOnly.Marshall();

[Benchmark]
public Container<DateTimeOffset> Unmarshall_DateTimeOffset() => _dateTimeOffset.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_DateTimeOffset() => _dateTimeOffset.Marshall();

[Benchmark]
public Container<DateTime> Unmarshall_DateTime() => _dateTime.Unmarshall();

[Benchmark]
public Dictionary<string, AttributeValue> Marshall_DateTime() => _dateTime.Marshall();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Amazon;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;
using BenchmarkDotNet.Attributes;

namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Benchmarks;

//public abstract class SG_VS_AWS_Benchmarker<T>(
// Func<T, Dictionary<string, AttributeValue>> marshaller,
// Func<Dictionary<string, AttributeValue>, T> unMarshaller
//)
//{
// private readonly DynamoDBContext _context = new DynamoDBContextBuilder()
// .WithDynamoDBClient(() => new AmazonDynamoDBClient(RegionEndpoint.EUWest1))
// .Build();
//
// private readonly ToDocumentConfig _dynamoDbOperationConfig = new() { Conversion = DynamoDBEntryConversion.V2 };
//
//
// [Benchmark]
// public Dictionary<string, AttributeValue> Marshall_AWS_Reflection() => _context
// .ToDocument(SingleElement, _dynamoDbOperationConfig)
// .ToAttributeMap(_dynamoDbOperationConfig.Conversion);
//
// [Benchmark]
// public T Unmarshall_AWS_Reflection() => _context.FromDocument<T>(Document.FromAttributeMap(AttributeValues));
//}
Loading