refactor: full generic DIAdapter workflow & universalRegistration abstraction

- Made UniversalChainBenchmark and UniversalChainAsyncBenchmark fully generic with strong typing for DIAdapter<TContainer>
- Moved all universalRegistration logic inside adapters; removed global function and typedef
- Replaced dynamic/object-based registration with type-safe generic contracts end-to-end
- Updated CLI and usage: all DI and scenarios are invoked via type-safe generics
- Fixed all analysis errors, Riverpod async/future usages, and imports for full Dart 3 compatibility
- All benchmarks fully pass for Cherrypick, GetIt, and Riverpod adapters
This commit is contained in:
Sergey Penkovsky
2025-08-07 14:11:29 +03:00
parent 54446868e4
commit 56bdb3946e
8 changed files with 223 additions and 204 deletions

View File

@@ -1,6 +1,9 @@
import 'dart:math';
import 'package:benchmark_di/cli/report/markdown_report.dart';
import 'package:cherrypick/cherrypick.dart';
import 'package:get_it/get_it.dart';
import 'package:riverpod/riverpod.dart' as rp;
import '../scenarios/universal_chain_module.dart';
import 'report/pretty_report.dart';
@@ -33,7 +36,7 @@ class BenchmarkCliRunner {
if (config.di == 'getit') {
final di = GetItAdapter();
if (scenario == UniversalScenario.asyncChain) {
final benchAsync = UniversalChainAsyncBenchmark(di,
final benchAsync = UniversalChainAsyncBenchmark<GetIt>(di,
chainCount: c, nestingDepth: d, mode: mode,
);
benchResult = await BenchmarkRunner.runAsync(
@@ -42,7 +45,7 @@ class BenchmarkCliRunner {
repeats: config.repeats,
);
} else {
final benchSync = UniversalChainBenchmark(di,
final benchSync = UniversalChainBenchmark<GetIt>(di,
chainCount: c, nestingDepth: d, mode: mode, scenario: scenario,
);
benchResult = await BenchmarkRunner.runSync(
@@ -54,7 +57,7 @@ class BenchmarkCliRunner {
} else if (config.di == 'riverpod') {
final di = RiverpodAdapter();
if (scenario == UniversalScenario.asyncChain) {
final benchAsync = UniversalChainAsyncBenchmark(di,
final benchAsync = UniversalChainAsyncBenchmark<Map<String, rp.ProviderBase<Object?>>>(di,
chainCount: c, nestingDepth: d, mode: mode,
);
benchResult = await BenchmarkRunner.runAsync(
@@ -63,7 +66,7 @@ class BenchmarkCliRunner {
repeats: config.repeats,
);
} else {
final benchSync = UniversalChainBenchmark(di,
final benchSync = UniversalChainBenchmark<Map<String, rp.ProviderBase<Object?>>>(di,
chainCount: c, nestingDepth: d, mode: mode, scenario: scenario,
);
benchResult = await BenchmarkRunner.runSync(
@@ -75,7 +78,7 @@ class BenchmarkCliRunner {
} else {
final di = CherrypickDIAdapter();
if (scenario == UniversalScenario.asyncChain) {
final benchAsync = UniversalChainAsyncBenchmark(di,
final benchAsync = UniversalChainAsyncBenchmark<Scope>(di,
chainCount: c, nestingDepth: d, mode: mode,
);
benchResult = await BenchmarkRunner.runAsync(
@@ -84,7 +87,7 @@ class BenchmarkCliRunner {
repeats: config.repeats,
);
} else {
final benchSync = UniversalChainBenchmark(di,
final benchSync = UniversalChainBenchmark<Scope>(di,
chainCount: c, nestingDepth: d, mode: mode, scenario: scenario,
);
benchResult = await BenchmarkRunner.runSync(