From bc0c117a16e702bb7006ce61701025bd531f9fe7 Mon Sep 17 00:00:00 2001 From: Stepami Date: Tue, 2 Dec 2025 14:15:54 +0300 Subject: [PATCH 1/3] benchmark error repro --- .../HydraScript.Benchmarks/GeneratedRegexContainer.cs | 11 ----------- .../HydraScript.Benchmarks.csproj | 6 ------ benchmarks/HydraScript.Benchmarks/InvokeBenchmark.cs | 2 +- src/HydraScript/HydraScript.csproj | 4 ---- src/HydraScript/Program.cs | 2 +- .../GeneratedRegexContainer.cs | 3 +-- .../HydraScript.Infrastructure.csproj | 4 ++++ .../ServiceCollectionExtensions.cs | 5 ++--- tests/HydraScript.IntegrationTests/TestHostFixture.cs | 2 +- .../Domain/FrontEnd/RegexLexerTests.cs | 1 + .../Domain/FrontEnd/StructureTests.cs | 1 + .../Domain/FrontEnd/TopDownParserTests.cs | 1 + 12 files changed, 13 insertions(+), 29 deletions(-) delete mode 100644 benchmarks/HydraScript.Benchmarks/GeneratedRegexContainer.cs rename src/{HydraScript => Infrastructure/HydraScript.Infrastructure}/GeneratedRegexContainer.cs (82%) diff --git a/benchmarks/HydraScript.Benchmarks/GeneratedRegexContainer.cs b/benchmarks/HydraScript.Benchmarks/GeneratedRegexContainer.cs deleted file mode 100644 index 980da6d0..00000000 --- a/benchmarks/HydraScript.Benchmarks/GeneratedRegexContainer.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.RegularExpressions; -using HydraScript.Domain.FrontEnd.Lexer; -using HydraScript.Infrastructure; - -namespace HydraScript.Benchmarks; - -internal sealed partial class GeneratedRegexContainer : IGeneratedRegexContainer -{ - [GeneratedRegex(PatternContainer.Value, RegexOptions.Compiled)] - public static partial Regex Regex { get; } -} \ No newline at end of file diff --git a/benchmarks/HydraScript.Benchmarks/HydraScript.Benchmarks.csproj b/benchmarks/HydraScript.Benchmarks/HydraScript.Benchmarks.csproj index 670f013f..443c4628 100644 --- a/benchmarks/HydraScript.Benchmarks/HydraScript.Benchmarks.csproj +++ b/benchmarks/HydraScript.Benchmarks/HydraScript.Benchmarks.csproj @@ -5,12 +5,6 @@ - - diff --git a/benchmarks/HydraScript.Benchmarks/InvokeBenchmark.cs b/benchmarks/HydraScript.Benchmarks/InvokeBenchmark.cs index 4f920553..73caeab1 100644 --- a/benchmarks/HydraScript.Benchmarks/InvokeBenchmark.cs +++ b/benchmarks/HydraScript.Benchmarks/InvokeBenchmark.cs @@ -27,7 +27,7 @@ public void GlobalSetup() { _provider = new ServiceCollection() .AddLogging(x => x.ClearProviders().AddProvider(NullLoggerProvider.Instance)) - .AddDomain() + .AddDomain() .AddApplication() .AddInfrastructure(dump: false, _updatableFileOptions.Value) .AddSingleton>(_updatableFileOptions) diff --git a/src/HydraScript/HydraScript.csproj b/src/HydraScript/HydraScript.csproj index 9ff91a96..d3044eda 100644 --- a/src/HydraScript/HydraScript.csproj +++ b/src/HydraScript/HydraScript.csproj @@ -7,10 +7,6 @@ - diff --git a/src/HydraScript/Program.cs b/src/HydraScript/Program.cs index f5841b52..35d7409d 100644 --- a/src/HydraScript/Program.cs +++ b/src/HydraScript/Program.cs @@ -28,7 +28,7 @@ private static ExecuteCommand GetCommand() private static ServiceProvider GetServiceProvider(FileInfo fileInfo, bool dump) => new ServiceCollection() .AddLogging(c => c.ClearProviders().AddZLoggerConsole()) - .AddDomain() + .AddDomain() .AddApplication() .AddInfrastructure(dump, fileInfo) .BuildServiceProvider(); diff --git a/src/HydraScript/GeneratedRegexContainer.cs b/src/Infrastructure/HydraScript.Infrastructure/GeneratedRegexContainer.cs similarity index 82% rename from src/HydraScript/GeneratedRegexContainer.cs rename to src/Infrastructure/HydraScript.Infrastructure/GeneratedRegexContainer.cs index 380937c6..0446b5e7 100644 --- a/src/HydraScript/GeneratedRegexContainer.cs +++ b/src/Infrastructure/HydraScript.Infrastructure/GeneratedRegexContainer.cs @@ -1,8 +1,7 @@ using System.Text.RegularExpressions; using HydraScript.Domain.FrontEnd.Lexer; -using HydraScript.Infrastructure; -namespace HydraScript; +namespace HydraScript.Infrastructure; public sealed partial class GeneratedRegexContainer : IGeneratedRegexContainer { diff --git a/src/Infrastructure/HydraScript.Infrastructure/HydraScript.Infrastructure.csproj b/src/Infrastructure/HydraScript.Infrastructure/HydraScript.Infrastructure.csproj index 35d96241..0e7bbf05 100644 --- a/src/Infrastructure/HydraScript.Infrastructure/HydraScript.Infrastructure.csproj +++ b/src/Infrastructure/HydraScript.Infrastructure/HydraScript.Infrastructure.csproj @@ -1,6 +1,10 @@  + diff --git a/src/Infrastructure/HydraScript.Infrastructure/ServiceCollectionExtensions.cs b/src/Infrastructure/HydraScript.Infrastructure/ServiceCollectionExtensions.cs index 78c93256..1f2c7501 100644 --- a/src/Infrastructure/HydraScript.Infrastructure/ServiceCollectionExtensions.cs +++ b/src/Infrastructure/HydraScript.Infrastructure/ServiceCollectionExtensions.cs @@ -15,12 +15,11 @@ namespace HydraScript.Infrastructure; public static class ServiceCollectionExtensions { - public static IServiceCollection AddDomain(this IServiceCollection services) - where TGeneratedRegexContainer : class, IGeneratedRegexContainer + public static IServiceCollection AddDomain(this IServiceCollection services) { services.AddSingleton(); services.AddSingleton(); - services.AddSingleton>(); + services.AddSingleton>(); services.AddSingleton(); services.AddSingleton(); diff --git a/tests/HydraScript.IntegrationTests/TestHostFixture.cs b/tests/HydraScript.IntegrationTests/TestHostFixture.cs index b2fbbf4f..9f9d644b 100644 --- a/tests/HydraScript.IntegrationTests/TestHostFixture.cs +++ b/tests/HydraScript.IntegrationTests/TestHostFixture.cs @@ -36,7 +36,7 @@ public void Dispose() public Runner GetRunner(Options options, Action? configureTestServices = null) { var services = new ServiceCollection() - .AddDomain() + .AddDomain() .AddApplication() .AddInfrastructure(options.Dump, new FileInfo(options.FileName)); const string serilogTemplate = "[{Timestamp:HH:mm:ss} {Level:u} [{SourceContext}]]{NewLine}{Message:lj} {Exception}"; diff --git a/tests/HydraScript.UnitTests/Domain/FrontEnd/RegexLexerTests.cs b/tests/HydraScript.UnitTests/Domain/FrontEnd/RegexLexerTests.cs index bcbe7767..e3e6ba59 100644 --- a/tests/HydraScript.UnitTests/Domain/FrontEnd/RegexLexerTests.cs +++ b/tests/HydraScript.UnitTests/Domain/FrontEnd/RegexLexerTests.cs @@ -3,6 +3,7 @@ using HydraScript.Domain.FrontEnd.Lexer; using HydraScript.Domain.FrontEnd.Lexer.Impl; using HydraScript.Domain.FrontEnd.Lexer.TokenTypes; +using HydraScript.Infrastructure; namespace HydraScript.UnitTests.Domain.FrontEnd; diff --git a/tests/HydraScript.UnitTests/Domain/FrontEnd/StructureTests.cs b/tests/HydraScript.UnitTests/Domain/FrontEnd/StructureTests.cs index c3e1314f..c8e681a3 100644 --- a/tests/HydraScript.UnitTests/Domain/FrontEnd/StructureTests.cs +++ b/tests/HydraScript.UnitTests/Domain/FrontEnd/StructureTests.cs @@ -2,6 +2,7 @@ using HydraScript.Domain.FrontEnd.Lexer; using HydraScript.Domain.FrontEnd.Lexer.Impl; using HydraScript.Domain.FrontEnd.Lexer.TokenTypes; +using HydraScript.Infrastructure; namespace HydraScript.UnitTests.Domain.FrontEnd; diff --git a/tests/HydraScript.UnitTests/Domain/FrontEnd/TopDownParserTests.cs b/tests/HydraScript.UnitTests/Domain/FrontEnd/TopDownParserTests.cs index 66fc7972..9016b3b6 100644 --- a/tests/HydraScript.UnitTests/Domain/FrontEnd/TopDownParserTests.cs +++ b/tests/HydraScript.UnitTests/Domain/FrontEnd/TopDownParserTests.cs @@ -1,6 +1,7 @@ using HydraScript.Domain.FrontEnd.Lexer.Impl; using HydraScript.Domain.FrontEnd.Parser; using HydraScript.Domain.FrontEnd.Parser.Impl; +using HydraScript.Infrastructure; namespace HydraScript.UnitTests.Domain.FrontEnd; From 2f9c6b130b2fdf3fa7d560cd3630709b419a5c9a Mon Sep 17 00:00:00 2001 From: Stepami Date: Tue, 21 Apr 2026 22:28:46 +0300 Subject: [PATCH 2/3] fix(infrastructure.lexer-regex-source-gen): compilation replaced project reference with compile include to avoid benchmark shared compilation based error Closes #234 --- .../HydraScript.Infrastructure.LexerRegexGenerator.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/HydraScript.Infrastructure.LexerRegexGenerator/HydraScript.Infrastructure.LexerRegexGenerator.csproj b/src/Infrastructure/HydraScript.Infrastructure.LexerRegexGenerator/HydraScript.Infrastructure.LexerRegexGenerator.csproj index acd99492..46dcae73 100644 --- a/src/Infrastructure/HydraScript.Infrastructure.LexerRegexGenerator/HydraScript.Infrastructure.LexerRegexGenerator.csproj +++ b/src/Infrastructure/HydraScript.Infrastructure.LexerRegexGenerator/HydraScript.Infrastructure.LexerRegexGenerator.csproj @@ -11,11 +11,11 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + From c1889c9bc99ffab39dd16a187acb224cbfa2285c Mon Sep 17 00:00:00 2001 From: Stepami Date: Tue, 21 Apr 2026 22:30:07 +0300 Subject: [PATCH 3/3] refactor(InvokeBenchmark): invocation randomly iterate over third of Samples Closes #236 --- .../HydraScript.Benchmarks/InvokeBenchmark.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/benchmarks/HydraScript.Benchmarks/InvokeBenchmark.cs b/benchmarks/HydraScript.Benchmarks/InvokeBenchmark.cs index 73caeab1..f20d8c6f 100644 --- a/benchmarks/HydraScript.Benchmarks/InvokeBenchmark.cs +++ b/benchmarks/HydraScript.Benchmarks/InvokeBenchmark.cs @@ -15,13 +15,17 @@ public class InvokeBenchmark { private ServiceProvider? _provider; private Executor? _executor; - private readonly UpdatableFileOptions _updatableFileOptions = new(new FileInfo(nameof(FileInfo))); - private readonly IReadOnlyList _scriptPaths = + private readonly UpdatableFileOptions _updatableFileOptions = new(new FileInfo(nameof(FileInfo))); + private readonly FileInfo[] _scriptPaths = Directory.GetFiles("Samples") .Select(x => new FileInfo(x)) .ToArray(); + private readonly int _benchmarkSize; + + public InvokeBenchmark() => _benchmarkSize = _scriptPaths.Length / 3; + [GlobalSetup] public void GlobalSetup() { @@ -35,13 +39,16 @@ public void GlobalSetup() _executor = _provider.GetRequiredService(); } + [IterationSetup] + public void IterationSetup() => Random.Shared.Shuffle(_scriptPaths); + [GlobalCleanup] public void GlobalCleanup() => _provider?.Dispose(); [Benchmark] public void Invoke() { - for (var i = 0; i < _scriptPaths.Count; i++) + for (var i = 0; i <_benchmarkSize; i++) { _updatableFileOptions.Update(_scriptPaths[i]); _executor?.Invoke();