Skip to content
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

Added validation benchmarks #7654

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ decompile
depersist
deprioritization
deprioritized
Diagnoser
Dispatchable
drawio
enisdenjo
Expand All @@ -57,6 +58,7 @@ Giroux
GraphiQL
graphqlconfig
graphqlrc
graphqls
graphyne
greendonut
Hasura
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageVersion Include="AutoMapper" Version="10.1.1" />
<PackageVersion Include="Basic.Reference.Assemblies.Net80" Version="1.7.8" />
<PackageVersion Include="Basic.Reference.Assemblies.Net90" Version="1.7.8" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="ChilliCream.Nitro.App" Version="$(NitroVersion)" />
<PackageVersion Include="ChilliCream.Testing.Utilities" Version="0.2.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
Expand Down
22 changes: 22 additions & 0 deletions src/HotChocolate/Core/benchmark/Benchmarks.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Validation.Benchmarks", "Validation.Benchmarks\HotChocolate.Validation.Benchmarks.csproj", "{545BB076-E7E0-42CB-84AC-4CE0A56962C1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{545BB076-E7E0-42CB-84AC-4CE0A56962C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{545BB076-E7E0-42CB-84AC-4CE0A56962C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{545BB076-E7E0-42CB-84AC-4CE0A56962C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{545BB076-E7E0-42CB-84AC-4CE0A56962C1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using BenchmarkDotNet.Attributes;
using HotChocolate.Execution;

namespace HotChocolate.Validation.Benchmarks;

[MemoryDiagnoser]
public class ExtraLargeSchema1Benchmark : ValidationBenchmarkBase
{
protected override string SchemaDocumentFile => "__resources__/extra-large-schema-1.graphqls";
protected override string DocumentFile => "__resources__/extra-large-schema-1-query.graphql";

[Benchmark]
public async Task<DocumentValidatorResult> ExtraLargeSchema1Validation()
{
return await Validator.ValidateAsync(
schema: Schema,
document: Document,
documentId: new OperationDocumentId("extra-large-schema-1-query"),
contextData: new Dictionary<string, object?>(),
onlyNonCacheable: false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Types\HotChocolate.Types.csproj" />
<ProjectReference Include="..\..\src\Validation\HotChocolate.Validation.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="__resources__\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using BenchmarkDotNet.Attributes;
using HotChocolate.Execution;

namespace HotChocolate.Validation.Benchmarks;

[MemoryDiagnoser]
public class LargeSchema1Benchmark : ValidationBenchmarkBase
{
protected override string SchemaDocumentFile => "__resources__/large-schema-1.graphqls";
protected override string DocumentFile => "__resources__/large-schema-1-query.graphql";

[Benchmark]
public async Task<DocumentValidatorResult> LargeSchema1Validation()
{
return await Validator.ValidateAsync(
schema: Schema,
document: Document,
documentId: new OperationDocumentId("large-schema-1-query"),
contextData: new Dictionary<string, object?>(),
onlyNonCacheable: false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using BenchmarkDotNet.Attributes;
using HotChocolate.Execution;

namespace HotChocolate.Validation.Benchmarks;

[MemoryDiagnoser]
public class LargeSchema2Benchmark : ValidationBenchmarkBase
{
protected override string SchemaDocumentFile => "__resources__/large-schema-2.graphqls";
protected override string DocumentFile => "__resources__/large-schema-2-query.graphql";

[Benchmark]
public async Task<DocumentValidatorResult> LargeSchema2Validation()
{
return await Validator.ValidateAsync(
schema: Schema,
document: Document,
documentId: new OperationDocumentId("large-schema-2-query"),
contextData: new Dictionary<string, object?>(),
onlyNonCacheable: false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// using BenchmarkDotNet.Attributes;
// using HotChocolate.Execution;
//
// namespace HotChocolate.Validation.Benchmarks;
//
// [MemoryDiagnoser]
// public class ManyFragmentsBenchmark : ValidationBenchmarkBase
// {
// protected override string SchemaDocumentFile => "__resources__/many-fragments.graphqls";
// protected override string DocumentFile => "__resources__/many-fragments-query.graphql";
//
// [Benchmark]
// public async Task<DocumentValidatorResult> ManyFragmentsValidation()
// {
// return await Validator.ValidateAsync(
// schema: Schema,
// document: Document,
// documentId: new OperationDocumentId("many-fragments-query"),
// contextData: new Dictionary<string, object?>(),
// onlyNonCacheable: false);
// }
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using BenchmarkDotNet.Running;

BenchmarkSwitcher
.FromAssembly(typeof(Program).Assembly)
.RunAllJoined(null, args);
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using BenchmarkDotNet.Attributes;
using HotChocolate.Language;
using HotChocolate.Types;
using Microsoft.Extensions.DependencyInjection;

namespace HotChocolate.Validation.Benchmarks;

public abstract class ValidationBenchmarkBase
{
protected abstract string SchemaDocumentFile { get; }
protected abstract string DocumentFile { get; }

protected ISchema Schema = null!;
protected IDocumentValidator Validator = null!;
protected DocumentNode Document = null!;

[GlobalSetup]
public void GlobalSetup()
{
var schemaDocument = Utf8GraphQLParser.Parse(File.ReadAllText(SchemaDocumentFile));

var schemaBuilder = SchemaBuilder.New();

// Register stubs for custom scalars.
var customScalars = schemaDocument.Definitions.OfType<ScalarTypeDefinitionNode>()
.Where(s => !Scalars.IsBuiltIn(s.Name.Value));

foreach (var scalar in customScalars)
{
schemaBuilder.AddType(new AnyType(scalar.Name.Value));
}

Schema = schemaBuilder
.AddDocument(schemaDocument)
.Use(next => next)
.Create();

Validator = new ServiceCollection()
.AddValidation()
.Services
.BuildServiceProvider()
.GetRequiredService<IDocumentValidatorFactory>()
.CreateValidator();

Document = Utf8GraphQLParser.Parse(File.ReadAllText(DocumentFile));
}
}
Loading
Loading