-
Couldn't load subscription status.
- Fork 1
improve performance of add changes #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hahn-kev
wants to merge
23
commits into
main
Choose a base branch
from
create-linq2db-repository
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
5634d4a
extract out an ICrdtRepository.cs interface
hahn-kev e6ff74c
create benchmarks project to enable dedicated running on benchmarks
hahn-kev c2d3c5f
setup git job comparison
hahn-kev 04c6e4d
replace CrdtRepositoryFactory with ICrdtRepositoryFactory
hahn-kev 8e08b90
introduce some more benchmarks and initial version of Linq2Db repo
hahn-kev a395f7a
make commit hash updates explicit
hahn-kev 7cefd25
add debug logging
hahn-kev 3367d9f
make debugging easier
hahn-kev 7b35041
add more repo tests to find bugs with the new repo
hahn-kev b5e9eb6
fix an issue with one test expecting the returned commit to have the …
hahn-kev 426bf8c
add 2 benchmarks, one for all at once
hahn-kev 2f3cfc6
don't use logging during a perf test, add a DataModelTestBase.cs conf…
hahn-kev 4a304a1
always run repo tests for both versions
hahn-kev 9a9901a
add dotTrace for easy profiling
hahn-kev 53a46ed
use new package version
hahn-kev 7c3b8d2
remove extra check projecting entities
hahn-kev e29dd8e
add a second benchmark for all changes
hahn-kev 9ad734c
disable linq2db logging when running as part of a perf test
hahn-kev d7414c3
increase change count in add change benchmarks
hahn-kev c593cc0
add test for `GetCurrentSnapshotByObjectId` and change it to use a co…
hahn-kev cd78ec9
lower dotnet version used for benchmarks
hahn-kev 54e7357
Merge branch 'main' into create-linq2db-repository
hahn-kev 733b622
resolve merge conflicts
hahn-kev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| using BenchmarkDotNet_GitCompare; | ||
| using BenchmarkDotNet.Attributes; | ||
| using BenchmarkDotNet.Diagnostics.dotMemory; | ||
| using BenchmarkDotNet.Diagnostics.dotTrace; | ||
| using BenchmarkDotNet.Engines; | ||
| using SIL.Harmony.Linq2db; | ||
| using SIL.Harmony.Tests; | ||
|
|
||
| namespace SIL.Harmony.Benchmarks; | ||
|
|
||
| [SimpleJob(RunStrategy.Throughput)] | ||
| [MemoryDiagnoser] | ||
| // [DotMemoryDiagnoser] | ||
| // [DotTraceDiagnoser] | ||
| // [GitJob(gitReference: "HEAD", id: "before", baseline: true)] | ||
| public class AddChangeBenchmarks | ||
| { | ||
| private DataModelTestBase _emptyDataModel = null!; | ||
| private Guid _clientId = Guid.NewGuid(); | ||
| public const int ActualChangeCount = 2000; | ||
| [Params(true, false)] | ||
| public bool UseLinq2DbRepo { get; set; } | ||
|
|
||
| [IterationSetup] | ||
| public void IterationSetup() | ||
| { | ||
| _emptyDataModel = new(alwaysValidate: false, performanceTest: true, useLinq2DbRepo: UseLinq2DbRepo); | ||
| _emptyDataModel.WriteNextChange(_emptyDataModel.SetWord(Guid.NewGuid(), "entity1")).GetAwaiter().GetResult(); | ||
| } | ||
|
|
||
| [Benchmark(OperationsPerInvoke = ActualChangeCount)] | ||
| public List<Commit> AddChanges() | ||
| { | ||
| var commits = new List<Commit>(); | ||
| for (var i = 0; i < ActualChangeCount; i++) | ||
| { | ||
| commits.Add(_emptyDataModel.WriteNextChange(_emptyDataModel.SetWord(Guid.NewGuid(), "entity1")).Result); | ||
| } | ||
|
|
||
| return commits; | ||
| } | ||
|
|
||
| [Benchmark(OperationsPerInvoke = ActualChangeCount)] | ||
| public Commit AddChangesAllAtOnce() | ||
| { | ||
| return _emptyDataModel.WriteChange(_clientId, DateTimeOffset.Now, Enumerable.Range(0, ActualChangeCount) | ||
| .Select(i => | ||
| _emptyDataModel.SetWord(Guid.NewGuid(), "entity1"))).Result; | ||
| } | ||
|
|
||
| [IterationCleanup] | ||
| public void IterationCleanup() | ||
| { | ||
| _emptyDataModel.DisposeAsync().GetAwaiter().GetResult(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| using BenchmarkDotNet_GitCompare; | ||
| using BenchmarkDotNet.Attributes; | ||
| using BenchmarkDotNet.Engines; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using SIL.Harmony.Core; | ||
| using SIL.Harmony.Db; | ||
| using SIL.Harmony.Linq2db; | ||
| using SIL.Harmony.Sample.Models; | ||
| using SIL.Harmony.Tests; | ||
|
|
||
| namespace SIL.Harmony.Benchmarks; | ||
|
|
||
| [SimpleJob(RunStrategy.Throughput)] | ||
| [MemoryDiagnoser] | ||
| // [GitJob(gitReference: "HEAD", id: "before", baseline: true)] | ||
| public class AddSnapshotsBenchmarks | ||
| { | ||
| private DataModelTestBase _emptyDataModel = null!; | ||
| private ICrdtRepository _repository = null!; | ||
| private Commit _commit = null!; | ||
|
|
||
| [Params(1000)] | ||
| public int SnapshotCount { get; set; } | ||
|
|
||
| [Params(true, false)] | ||
| public bool UseLinq2DbRepo { get; set; } | ||
|
|
||
| [IterationSetup] | ||
| public void IterationSetup() | ||
| { | ||
| _emptyDataModel = new(alwaysValidate: false, | ||
| performanceTest: true, useLinq2DbRepo: UseLinq2DbRepo); | ||
| var crdtRepositoryFactory = _emptyDataModel.Services.GetRequiredService<ICrdtRepositoryFactory>(); | ||
| _repository = crdtRepositoryFactory.CreateRepositorySync(); | ||
| _repository.AddCommit(_commit = new Commit(Guid.NewGuid()) | ||
| { | ||
| ClientId = Guid.NewGuid(), | ||
| HybridDateTime = new HybridDateTime(DateTimeOffset.Now, 0), | ||
| }).GetAwaiter().GetResult(); | ||
| } | ||
|
|
||
| [Benchmark(OperationsPerInvoke = 1000)] | ||
| public void AddSnapshotsOneAtATime() | ||
| { | ||
| for (var i = 0; i < SnapshotCount; i++) | ||
| { | ||
| _repository.AddSnapshots([ | ||
| new ObjectSnapshot(new Word() | ||
| { | ||
| Id = Guid.NewGuid(), | ||
| Text = "test", | ||
| }, _commit, true) | ||
| ]).GetAwaiter().GetResult(); | ||
| } | ||
| } | ||
|
|
||
| [Benchmark(OperationsPerInvoke = 1000)] | ||
| public void AddSnapshotsAllAtOnce() | ||
| { | ||
| var snapshots = Enumerable.Range(0, SnapshotCount) | ||
| .Select(i => new ObjectSnapshot(new Word() | ||
| { | ||
| Id = Guid.NewGuid(), | ||
| Text = "test", | ||
| }, | ||
| _commit, | ||
| true)) | ||
| .ToArray(); | ||
|
|
||
| _repository.AddSnapshots(snapshots).GetAwaiter().GetResult(); | ||
| } | ||
|
|
||
| [IterationCleanup] | ||
| public void IterationCleanup() | ||
| { | ||
| _repository.Dispose(); | ||
| _emptyDataModel.DisposeAsync().GetAwaiter().GetResult(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| using BenchmarkDotNet.Running; | ||
| using SIL.Harmony.Tests.Benchmarks; | ||
|
|
||
| BenchmarkSwitcher.FromAssemblies([typeof(Program).Assembly, typeof(ChangeThroughput).Assembly]).Run(args); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="BenchmarkDotNet" /> | ||
| <PackageReference Include="BenchmarkDotNet.Diagnostics.dotMemory" /> | ||
| <PackageReference Include="BenchmarkDotNet.Diagnostics.dotTrace" /> | ||
| <PackageReference Include="Enterprize1.BenchmarkDotNet.GitCompare" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\SIL.Harmony.Tests\SIL.Harmony.Tests.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix markdownlint MD034 and align run command with CI SDK.
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
192-192: Bare URL used
(MD034, no-bare-urls)
🤖 Prompt for AI Agents