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
3 changes: 2 additions & 1 deletion src/SIL.Harmony.Sample/CrdtSampleKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public static IServiceCollection AddCrdtDataSample(this IServiceCollection servi
{
//this ensures that Ef Conversion methods will not be cached across different IoC containers
//this can show up as the second instance using the JsonSerializerOptions from the first container
//only needed for testing scenarios
//But, for testing scenarios (performanceTest: true) this essentially restores EF Core's default service-provider caching
//(which is otherwise disabled for test isolation) and thus matches real ASP.NET Core app config
builder.EnableServiceProviderCaching(performanceTest);
builder.UseLinqToDbCrdt(provider);
optionsBuilder(builder);
Expand Down
5 changes: 4 additions & 1 deletion src/SIL.Harmony.Tests/DataModelPerformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static async Task<TimeSpan> MeasureTime(Func<Task> action, int iteration
public async Task SimpleAddChangePerformanceTest()
{
//disable validation because it's slow
var dataModelTest = new DataModelTestBase(alwaysValidate: false);
var dataModelTest = new DataModelTestBase(alwaysValidate: false, performanceTest: true);
// warmup the code, this causes jit to run and keeps our actual test below consistent
await dataModelTest.WriteNextChange(dataModelTest.SetWord(Guid.NewGuid(), "entity 0"));
var runtimeAddChange1Snapshot = await MeasureTime(() => dataModelTest.WriteNextChange(dataModelTest.SetWord(Guid.NewGuid(), "entity 1")).AsTask());
Expand All @@ -87,6 +87,9 @@ public async Task SimpleAddChangePerformanceTest()
//fork the database, this creates a new DbContext which does not have a cache of all the snapshots created above
//that cache causes DetectChanges (used by SaveChanges) to be slower than it should be
dataModelTest = dataModelTest.ForkDatabase(false);
//warmup the forked context too — it has a fresh ServiceProvider/DbContext/DataModel,
//so the first WriteNextChange pays EF Core query-compilation cost that the measurement shouldn't include
await dataModelTest.WriteNextChange(dataModelTest.SetWord(Guid.NewGuid(), "entity warmup"));

await StartTrace();
var runtimeAddChange10000Snapshots = await MeasureTime(() => dataModelTest.WriteNextChange(dataModelTest.SetWord(Guid.NewGuid(), "entity1")).AsTask());
Expand Down
Loading