mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-24 13:47:24 +00:00
Compare commits
38 Commits
cherrypick
...
talker_che
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4c5fd922e | ||
|
|
8870b8ce54 | ||
|
|
298cb65ac8 | ||
|
|
1b9db31c13 | ||
|
|
ca3cd2c8fd | ||
|
|
c91e15319b | ||
|
|
99e662124f | ||
|
|
03f54981f3 | ||
|
|
349efe6ba6 | ||
|
|
c2f0e027b6 | ||
|
|
f85036d20f | ||
|
|
db4d128d04 | ||
|
|
2c4e2ed251 | ||
|
|
7b4642f407 | ||
|
|
7d45d00d6a | ||
|
|
884df50a34 | ||
|
|
5710af2f9b | ||
|
|
9312ef46ea | ||
|
|
900cd68663 | ||
|
|
57e4196b95 | ||
|
|
358da8f96b | ||
|
|
ea2b6687f4 | ||
|
|
df00a2a5d2 | ||
|
|
d5983a4a0b | ||
|
|
125bccfa5a | ||
|
|
12b97c9368 | ||
|
|
424aaa3e22 | ||
|
|
2ec3a86a2f | ||
|
|
efed72cc39 | ||
|
|
4dc9e269cd | ||
|
|
d153ab4255 | ||
|
|
6924ccd07b | ||
|
|
26b843f791 | ||
|
|
8eafba4e4b | ||
|
|
ad6e9bbc3d | ||
|
|
bea8affcab | ||
|
|
1d7b9a9166 | ||
|
|
016c212063 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -18,5 +18,7 @@ pubspec_overrides.yaml
|
|||||||
melos_cherrypick.iml
|
melos_cherrypick.iml
|
||||||
melos_cherrypick_workspace.iml
|
melos_cherrypick_workspace.iml
|
||||||
melos_cherrypick_flutter.iml
|
melos_cherrypick_flutter.iml
|
||||||
|
melos_benchmark_di.iml
|
||||||
|
melos_talker_cherrypick_logger.iml
|
||||||
|
|
||||||
coverage
|
coverage
|
||||||
180
CHANGELOG.md
180
CHANGELOG.md
@@ -3,6 +3,186 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## 2025-08-15
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Packages with breaking changes:
|
||||||
|
|
||||||
|
- There are no breaking changes in this release.
|
||||||
|
|
||||||
|
Packages with other changes:
|
||||||
|
|
||||||
|
- [`cherrypick` - `v3.0.0-dev.10`](#cherrypick---v300-dev10)
|
||||||
|
- [`cherrypick_annotations` - `v1.1.2-dev.1`](#cherrypick_annotations---v112-dev1)
|
||||||
|
- [`cherrypick_flutter` - `v1.1.3-dev.10`](#cherrypick_flutter---v113-dev10)
|
||||||
|
- [`cherrypick_generator` - `v2.0.0-dev.1`](#cherrypick_generator---v200-dev1)
|
||||||
|
- [`talker_cherrypick_logger` - `v1.1.0-dev.5`](#talker_cherrypick_logger---v110-dev5)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### `cherrypick` - `v3.0.0-dev.10`
|
||||||
|
|
||||||
|
- **DOCS**(pub): update homepage and documentation URLs in pubspec.yaml to new official site.
|
||||||
|
|
||||||
|
#### `cherrypick_annotations` - `v1.1.2-dev.1`
|
||||||
|
|
||||||
|
- **DOCS**(pub): update homepage and documentation URLs in pubspec.yaml to new official site.
|
||||||
|
|
||||||
|
#### `cherrypick_flutter` - `v1.1.3-dev.10`
|
||||||
|
|
||||||
|
- **DOCS**(pub): update homepage and documentation URLs in pubspec.yaml to new official site.
|
||||||
|
|
||||||
|
#### `cherrypick_generator` - `v2.0.0-dev.1`
|
||||||
|
|
||||||
|
- **DOCS**(pub): update homepage and documentation URLs in pubspec.yaml to new official site.
|
||||||
|
|
||||||
|
#### `talker_cherrypick_logger` - `v1.1.0-dev.5`
|
||||||
|
|
||||||
|
- **DOCS**(pub): update homepage and documentation URLs in pubspec.yaml to new official site.
|
||||||
|
|
||||||
|
|
||||||
|
## 2025-08-13
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Packages with breaking changes:
|
||||||
|
|
||||||
|
- There are no breaking changes in this release.
|
||||||
|
|
||||||
|
Packages with other changes:
|
||||||
|
|
||||||
|
- [`talker_cherrypick_logger` - `v1.1.0-dev.4`](#talker_cherrypick_logger---v110-dev4)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### `talker_cherrypick_logger` - `v1.1.0-dev.4`
|
||||||
|
|
||||||
|
- **DOCS**(readme): update install instructions to use pub.dev as default method and remove obsolete git example.
|
||||||
|
|
||||||
|
|
||||||
|
## 2025-08-13
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Packages with breaking changes:
|
||||||
|
|
||||||
|
- There are no breaking changes in this release.
|
||||||
|
|
||||||
|
Packages with other changes:
|
||||||
|
|
||||||
|
- [`talker_cherrypick_logger` - `v1.1.0-dev.3`](#talker_cherrypick_logger---v110-dev3)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### `talker_cherrypick_logger` - `v1.1.0-dev.3`
|
||||||
|
|
||||||
|
|
||||||
|
## 2025-08-13
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Packages with breaking changes:
|
||||||
|
|
||||||
|
- There are no breaking changes in this release.
|
||||||
|
|
||||||
|
Packages with other changes:
|
||||||
|
|
||||||
|
- [`talker_cherrypick_logger` - `v1.1.0-dev.2`](#talker_cherrypick_logger---v110-dev2)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### `talker_cherrypick_logger` - `v1.1.0-dev.2`
|
||||||
|
|
||||||
|
- Bump "talker_cherrypick_logger" to `1.1.0-dev.2`.
|
||||||
|
|
||||||
|
|
||||||
|
## 2025-08-13
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Packages with breaking changes:
|
||||||
|
|
||||||
|
- [`cherrypick_generator` - `v2.0.0-dev.0`](#cherrypick_generator---v200-dev0)
|
||||||
|
|
||||||
|
Packages with other changes:
|
||||||
|
|
||||||
|
- [`cherrypick` - `v3.0.0-dev.9`](#cherrypick---v300-dev9)
|
||||||
|
- [`cherrypick_annotations` - `v1.1.2-dev.0`](#cherrypick_annotations---v112-dev0)
|
||||||
|
- [`cherrypick_flutter` - `v1.1.3-dev.9`](#cherrypick_flutter---v113-dev9)
|
||||||
|
- [`talker_cherrypick_logger` - `v1.1.0-dev.0`](#talker_cherrypick_logger---v110-dev0)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### `cherrypick_generator` - `v2.0.0-dev.0`
|
||||||
|
|
||||||
|
- **BREAKING** **DOCS**(generator): improve and unify English documentation and examples for all DI source files.
|
||||||
|
|
||||||
|
#### `cherrypick` - `v3.0.0-dev.9`
|
||||||
|
|
||||||
|
- **DOCS**(readme): add talker_cherrypick_logger to Additional Modules section.
|
||||||
|
- **DOCS**(api): improve all DI core code documentation with English dartdoc and examples.
|
||||||
|
|
||||||
|
#### `cherrypick_annotations` - `v1.1.2-dev.0`
|
||||||
|
|
||||||
|
- **DOCS**(annotations): unify and improve English DartDoc for all DI annotations.
|
||||||
|
|
||||||
|
#### `cherrypick_flutter` - `v1.1.3-dev.9`
|
||||||
|
|
||||||
|
- **DOCS**(provider): add detailed English API documentation for CherryPickProvider Flutter integration.
|
||||||
|
|
||||||
|
#### `talker_cherrypick_logger` - `v1.1.0-dev.0`
|
||||||
|
|
||||||
|
- **FEAT**(logging): add talker_dio_logger and talker_bloc_logger integration, improve cherrypick logger structure, add UI log screen for DI and network/bloc debug.
|
||||||
|
- **DOCS**: add full English documentation and usage guide to README.md.
|
||||||
|
- **DOCS**: add detailed English documentation and usage examples for TalkerCherryPickObserver.
|
||||||
|
|
||||||
|
|
||||||
|
## 2025-08-12
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Packages with breaking changes:
|
||||||
|
|
||||||
|
- There are no breaking changes in this release.
|
||||||
|
|
||||||
|
Packages with other changes:
|
||||||
|
|
||||||
|
- [`cherrypick` - `v3.0.0-dev.8`](#cherrypick---v300-dev8)
|
||||||
|
- [`cherrypick_flutter` - `v1.1.3-dev.8`](#cherrypick_flutter---v113-dev8)
|
||||||
|
|
||||||
|
Packages with dependency updates only:
|
||||||
|
|
||||||
|
> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project.
|
||||||
|
|
||||||
|
- `cherrypick_flutter` - `v1.1.3-dev.8`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### `cherrypick` - `v3.0.0-dev.8`
|
||||||
|
|
||||||
|
- **REFACTOR**(tests): replace MockLogger with MockObserver in scope tests to align with updated observer API.
|
||||||
|
- **FIX**(doc): remove hide symbol.
|
||||||
|
- **FEAT**(core): add full DI lifecycle observability via onInstanceDisposed.
|
||||||
|
- **DOCS**(logging): update Logging section in README with modern Observer usage and Talker integration examples.
|
||||||
|
- **DOCS**(observer): improve documentation, translate all comments to English, add usage examples.
|
||||||
|
- **DOCS**(README): add section with overview table for additional modules.
|
||||||
|
- **DOCS**(README): refactor structure and improve clarity of advanced features.
|
||||||
|
- **DOCS**(README): add 'Hierarchical Subscopes' section and update structure for advanced features clarity.
|
||||||
|
|
||||||
|
|
||||||
## 2025-08-11
|
## 2025-08-11
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ class UniversalChainBenchmark<TContainer> extends BenchmarkBase {
|
|||||||
_childDi!.resolve<UniversalService>();
|
_childDi!.resolve<UniversalService>();
|
||||||
break;
|
break;
|
||||||
case UniversalScenario.asyncChain:
|
case UniversalScenario.asyncChain:
|
||||||
throw UnsupportedError('asyncChain supported only in UniversalChainAsyncBenchmark');
|
throw UnsupportedError(
|
||||||
|
'asyncChain supported only in UniversalChainAsyncBenchmark');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,11 @@ class BenchmarkCliRunner {
|
|||||||
if (config.di == 'getit') {
|
if (config.di == 'getit') {
|
||||||
final di = GetItAdapter();
|
final di = GetItAdapter();
|
||||||
if (scenario == UniversalScenario.asyncChain) {
|
if (scenario == UniversalScenario.asyncChain) {
|
||||||
final benchAsync = UniversalChainAsyncBenchmark<GetIt>(di,
|
final benchAsync = UniversalChainAsyncBenchmark<GetIt>(
|
||||||
chainCount: c, nestingDepth: d, mode: mode,
|
di,
|
||||||
|
chainCount: c,
|
||||||
|
nestingDepth: d,
|
||||||
|
mode: mode,
|
||||||
);
|
);
|
||||||
benchResult = await BenchmarkRunner.runAsync(
|
benchResult = await BenchmarkRunner.runAsync(
|
||||||
benchmark: benchAsync,
|
benchmark: benchAsync,
|
||||||
@@ -45,8 +48,12 @@ class BenchmarkCliRunner {
|
|||||||
repeats: config.repeats,
|
repeats: config.repeats,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
final benchSync = UniversalChainBenchmark<GetIt>(di,
|
final benchSync = UniversalChainBenchmark<GetIt>(
|
||||||
chainCount: c, nestingDepth: d, mode: mode, scenario: scenario,
|
di,
|
||||||
|
chainCount: c,
|
||||||
|
nestingDepth: d,
|
||||||
|
mode: mode,
|
||||||
|
scenario: scenario,
|
||||||
);
|
);
|
||||||
benchResult = await BenchmarkRunner.runSync(
|
benchResult = await BenchmarkRunner.runSync(
|
||||||
benchmark: benchSync,
|
benchmark: benchSync,
|
||||||
@@ -57,8 +64,12 @@ class BenchmarkCliRunner {
|
|||||||
} else if (config.di == 'riverpod') {
|
} else if (config.di == 'riverpod') {
|
||||||
final di = RiverpodAdapter();
|
final di = RiverpodAdapter();
|
||||||
if (scenario == UniversalScenario.asyncChain) {
|
if (scenario == UniversalScenario.asyncChain) {
|
||||||
final benchAsync = UniversalChainAsyncBenchmark<Map<String, rp.ProviderBase<Object?>>>(di,
|
final benchAsync = UniversalChainAsyncBenchmark<
|
||||||
chainCount: c, nestingDepth: d, mode: mode,
|
Map<String, rp.ProviderBase<Object?>>>(
|
||||||
|
di,
|
||||||
|
chainCount: c,
|
||||||
|
nestingDepth: d,
|
||||||
|
mode: mode,
|
||||||
);
|
);
|
||||||
benchResult = await BenchmarkRunner.runAsync(
|
benchResult = await BenchmarkRunner.runAsync(
|
||||||
benchmark: benchAsync,
|
benchmark: benchAsync,
|
||||||
@@ -66,8 +77,13 @@ class BenchmarkCliRunner {
|
|||||||
repeats: config.repeats,
|
repeats: config.repeats,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
final benchSync = UniversalChainBenchmark<Map<String, rp.ProviderBase<Object?>>>(di,
|
final benchSync = UniversalChainBenchmark<
|
||||||
chainCount: c, nestingDepth: d, mode: mode, scenario: scenario,
|
Map<String, rp.ProviderBase<Object?>>>(
|
||||||
|
di,
|
||||||
|
chainCount: c,
|
||||||
|
nestingDepth: d,
|
||||||
|
mode: mode,
|
||||||
|
scenario: scenario,
|
||||||
);
|
);
|
||||||
benchResult = await BenchmarkRunner.runSync(
|
benchResult = await BenchmarkRunner.runSync(
|
||||||
benchmark: benchSync,
|
benchmark: benchSync,
|
||||||
@@ -78,8 +94,11 @@ class BenchmarkCliRunner {
|
|||||||
} else {
|
} else {
|
||||||
final di = CherrypickDIAdapter();
|
final di = CherrypickDIAdapter();
|
||||||
if (scenario == UniversalScenario.asyncChain) {
|
if (scenario == UniversalScenario.asyncChain) {
|
||||||
final benchAsync = UniversalChainAsyncBenchmark<Scope>(di,
|
final benchAsync = UniversalChainAsyncBenchmark<Scope>(
|
||||||
chainCount: c, nestingDepth: d, mode: mode,
|
di,
|
||||||
|
chainCount: c,
|
||||||
|
nestingDepth: d,
|
||||||
|
mode: mode,
|
||||||
);
|
);
|
||||||
benchResult = await BenchmarkRunner.runAsync(
|
benchResult = await BenchmarkRunner.runAsync(
|
||||||
benchmark: benchAsync,
|
benchmark: benchAsync,
|
||||||
@@ -87,8 +106,12 @@ class BenchmarkCliRunner {
|
|||||||
repeats: config.repeats,
|
repeats: config.repeats,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
final benchSync = UniversalChainBenchmark<Scope>(di,
|
final benchSync = UniversalChainBenchmark<Scope>(
|
||||||
chainCount: c, nestingDepth: d, mode: mode, scenario: scenario,
|
di,
|
||||||
|
chainCount: c,
|
||||||
|
nestingDepth: d,
|
||||||
|
mode: mode,
|
||||||
|
scenario: scenario,
|
||||||
);
|
);
|
||||||
benchResult = await BenchmarkRunner.runSync(
|
benchResult = await BenchmarkRunner.runSync(
|
||||||
benchmark: benchSync,
|
benchmark: benchSync,
|
||||||
@@ -103,7 +126,11 @@ class BenchmarkCliRunner {
|
|||||||
var median = timings[timings.length ~/ 2];
|
var median = timings[timings.length ~/ 2];
|
||||||
var minVal = timings.first;
|
var minVal = timings.first;
|
||||||
var maxVal = timings.last;
|
var maxVal = timings.last;
|
||||||
var stddev = timings.isEmpty ? 0 : sqrt(timings.map((x) => pow(x - mean, 2)).reduce((a, b) => a + b) / timings.length);
|
var stddev = timings.isEmpty
|
||||||
|
? 0
|
||||||
|
: sqrt(
|
||||||
|
timings.map((x) => pow(x - mean, 2)).reduce((a, b) => a + b) /
|
||||||
|
timings.length);
|
||||||
results.add({
|
results.add({
|
||||||
'benchmark': 'Universal_$bench',
|
'benchmark': 'Universal_$bench',
|
||||||
'chainCount': c,
|
'chainCount': c,
|
||||||
@@ -128,6 +155,7 @@ class BenchmarkCliRunner {
|
|||||||
'json': JsonReport(),
|
'json': JsonReport(),
|
||||||
'markdown': MarkdownReport(),
|
'markdown': MarkdownReport(),
|
||||||
};
|
};
|
||||||
print(reportGenerators[config.format]?.render(results) ?? PrettyReport().render(results));
|
print(reportGenerators[config.format]?.render(results) ??
|
||||||
|
PrettyReport().render(results));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,14 +8,19 @@ import 'package:benchmark_di/scenarios/universal_scenario.dart';
|
|||||||
enum UniversalBenchmark {
|
enum UniversalBenchmark {
|
||||||
/// Simple singleton registration benchmark
|
/// Simple singleton registration benchmark
|
||||||
registerSingleton,
|
registerSingleton,
|
||||||
|
|
||||||
/// Chain of singleton dependencies
|
/// Chain of singleton dependencies
|
||||||
chainSingleton,
|
chainSingleton,
|
||||||
|
|
||||||
/// Chain using factories
|
/// Chain using factories
|
||||||
chainFactory,
|
chainFactory,
|
||||||
|
|
||||||
/// Async chain resolution
|
/// Async chain resolution
|
||||||
chainAsync,
|
chainAsync,
|
||||||
|
|
||||||
/// Named registration benchmark
|
/// Named registration benchmark
|
||||||
named,
|
named,
|
||||||
|
|
||||||
/// Override/child-scope benchmark
|
/// Override/child-scope benchmark
|
||||||
override,
|
override,
|
||||||
}
|
}
|
||||||
@@ -65,23 +70,32 @@ T parseEnum<T>(String value, List<T> values, T defaultValue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parses comma-separated integer list from [s].
|
/// Parses comma-separated integer list from [s].
|
||||||
List<int> parseIntList(String s) =>
|
List<int> parseIntList(String s) => s
|
||||||
s.split(',').map((e) => int.tryParse(e.trim()) ?? 0).where((x) => x > 0).toList();
|
.split(',')
|
||||||
|
.map((e) => int.tryParse(e.trim()) ?? 0)
|
||||||
|
.where((x) => x > 0)
|
||||||
|
.toList();
|
||||||
|
|
||||||
/// CLI config describing what and how to benchmark.
|
/// CLI config describing what and how to benchmark.
|
||||||
class BenchmarkCliConfig {
|
class BenchmarkCliConfig {
|
||||||
/// Benchmarks enabled to run (scenarios).
|
/// Benchmarks enabled to run (scenarios).
|
||||||
final List<UniversalBenchmark> benchesToRun;
|
final List<UniversalBenchmark> benchesToRun;
|
||||||
|
|
||||||
/// List of chain counts (parallel, per test).
|
/// List of chain counts (parallel, per test).
|
||||||
final List<int> chainCounts;
|
final List<int> chainCounts;
|
||||||
|
|
||||||
/// List of nesting depths (max chain length, per test).
|
/// List of nesting depths (max chain length, per test).
|
||||||
final List<int> nestDepths;
|
final List<int> nestDepths;
|
||||||
|
|
||||||
/// How many times to repeat each trial.
|
/// How many times to repeat each trial.
|
||||||
final int repeats;
|
final int repeats;
|
||||||
|
|
||||||
/// How many times to warm-up before measuring.
|
/// How many times to warm-up before measuring.
|
||||||
final int warmups;
|
final int warmups;
|
||||||
|
|
||||||
/// Output report format.
|
/// Output report format.
|
||||||
final String format;
|
final String format;
|
||||||
|
|
||||||
/// Name of DI implementation ("cherrypick" or "getit")
|
/// Name of DI implementation ("cherrypick" or "getit")
|
||||||
final String di;
|
final String di;
|
||||||
BenchmarkCliConfig({
|
BenchmarkCliConfig({
|
||||||
@@ -105,7 +119,9 @@ BenchmarkCliConfig parseBenchmarkCli(List<String> args) {
|
|||||||
..addOption('repeat', abbr: 'r', defaultsTo: '2')
|
..addOption('repeat', abbr: 'r', defaultsTo: '2')
|
||||||
..addOption('warmup', abbr: 'w', defaultsTo: '1')
|
..addOption('warmup', abbr: 'w', defaultsTo: '1')
|
||||||
..addOption('format', abbr: 'f', defaultsTo: 'pretty')
|
..addOption('format', abbr: 'f', defaultsTo: 'pretty')
|
||||||
..addOption('di', defaultsTo: 'cherrypick', help: 'DI implementation: cherrypick, getit or riverpod')
|
..addOption('di',
|
||||||
|
defaultsTo: 'cherrypick',
|
||||||
|
help: 'DI implementation: cherrypick, getit or riverpod')
|
||||||
..addFlag('help', abbr: 'h', negatable: false, help: 'Show help');
|
..addFlag('help', abbr: 'h', negatable: false, help: 'Show help');
|
||||||
final result = parser.parse(args);
|
final result = parser.parse(args);
|
||||||
if (result['help'] == true) {
|
if (result['help'] == true) {
|
||||||
|
|||||||
@@ -5,20 +5,32 @@ class CsvReport extends ReportGenerator {
|
|||||||
/// List of all keys/columns to include in the CSV output.
|
/// List of all keys/columns to include in the CSV output.
|
||||||
@override
|
@override
|
||||||
final List<String> keys = [
|
final List<String> keys = [
|
||||||
'benchmark','chainCount','nestingDepth','mean_us','median_us','stddev_us',
|
'benchmark',
|
||||||
'min_us','max_us','trials','timings_us','memory_diff_kb','delta_peak_kb','peak_rss_kb'
|
'chainCount',
|
||||||
|
'nestingDepth',
|
||||||
|
'mean_us',
|
||||||
|
'median_us',
|
||||||
|
'stddev_us',
|
||||||
|
'min_us',
|
||||||
|
'max_us',
|
||||||
|
'trials',
|
||||||
|
'timings_us',
|
||||||
|
'memory_diff_kb',
|
||||||
|
'delta_peak_kb',
|
||||||
|
'peak_rss_kb'
|
||||||
];
|
];
|
||||||
|
|
||||||
/// Renders rows as a CSV table string.
|
/// Renders rows as a CSV table string.
|
||||||
@override
|
@override
|
||||||
String render(List<Map<String, dynamic>> rows) {
|
String render(List<Map<String, dynamic>> rows) {
|
||||||
final header = keys.join(',');
|
final header = keys.join(',');
|
||||||
final lines = rows.map((r) =>
|
final lines = rows
|
||||||
keys.map((k) {
|
.map((r) => keys.map((k) {
|
||||||
final v = r[k];
|
final v = r[k];
|
||||||
if (v is List) return '"${v.join(';')}"';
|
if (v is List) return '"${v.join(';')}"';
|
||||||
return (v ?? '').toString();
|
return (v ?? '').toString();
|
||||||
}).join(',')
|
}).join(','))
|
||||||
).toList();
|
.toList();
|
||||||
return ([header] + lines).join('\n');
|
return ([header] + lines).join('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ class JsonReport extends ReportGenerator {
|
|||||||
/// No specific keys; outputs all fields in raw map.
|
/// No specific keys; outputs all fields in raw map.
|
||||||
@override
|
@override
|
||||||
List<String> get keys => [];
|
List<String> get keys => [];
|
||||||
|
|
||||||
/// Renders all result rows as a pretty-printed JSON array.
|
/// Renders all result rows as a pretty-printed JSON array.
|
||||||
@override
|
@override
|
||||||
String render(List<Map<String, dynamic>> rows) {
|
String render(List<Map<String, dynamic>> rows) {
|
||||||
|
|||||||
@@ -7,25 +7,46 @@ class MarkdownReport extends ReportGenerator {
|
|||||||
/// List of columns (keys) to show in the Markdown table.
|
/// List of columns (keys) to show in the Markdown table.
|
||||||
@override
|
@override
|
||||||
final List<String> keys = [
|
final List<String> keys = [
|
||||||
'benchmark','chainCount','nestingDepth','mean_us','median_us','stddev_us',
|
'benchmark',
|
||||||
'min_us','max_us','trials','memory_diff_kb','delta_peak_kb','peak_rss_kb'
|
'chainCount',
|
||||||
|
'nestingDepth',
|
||||||
|
'mean_us',
|
||||||
|
'median_us',
|
||||||
|
'stddev_us',
|
||||||
|
'min_us',
|
||||||
|
'max_us',
|
||||||
|
'trials',
|
||||||
|
'memory_diff_kb',
|
||||||
|
'delta_peak_kb',
|
||||||
|
'peak_rss_kb'
|
||||||
];
|
];
|
||||||
|
|
||||||
/// Friendly display names for each benchmark type.
|
/// Friendly display names for each benchmark type.
|
||||||
static const nameMap = {
|
static const nameMap = {
|
||||||
'Universal_UniversalBenchmark.registerSingleton':'RegisterSingleton',
|
'Universal_UniversalBenchmark.registerSingleton': 'RegisterSingleton',
|
||||||
'Universal_UniversalBenchmark.chainSingleton':'ChainSingleton',
|
'Universal_UniversalBenchmark.chainSingleton': 'ChainSingleton',
|
||||||
'Universal_UniversalBenchmark.chainFactory':'ChainFactory',
|
'Universal_UniversalBenchmark.chainFactory': 'ChainFactory',
|
||||||
'Universal_UniversalBenchmark.chainAsync':'AsyncChain',
|
'Universal_UniversalBenchmark.chainAsync': 'AsyncChain',
|
||||||
'Universal_UniversalBenchmark.named':'Named',
|
'Universal_UniversalBenchmark.named': 'Named',
|
||||||
'Universal_UniversalBenchmark.override':'Override',
|
'Universal_UniversalBenchmark.override': 'Override',
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Renders all results as a formatted Markdown table with aligned columns and a legend.
|
/// Renders all results as a formatted Markdown table with aligned columns and a legend.
|
||||||
@override
|
@override
|
||||||
String render(List<Map<String, dynamic>> rows) {
|
String render(List<Map<String, dynamic>> rows) {
|
||||||
final headers = [
|
final headers = [
|
||||||
'Benchmark', 'Chain Count', 'Depth', 'Mean (us)', 'Median', 'Stddev', 'Min', 'Max', 'N', 'ΔRSS(KB)', 'ΔPeak(KB)', 'PeakRSS(KB)'
|
'Benchmark',
|
||||||
|
'Chain Count',
|
||||||
|
'Depth',
|
||||||
|
'Mean (us)',
|
||||||
|
'Median',
|
||||||
|
'Stddev',
|
||||||
|
'Min',
|
||||||
|
'Max',
|
||||||
|
'N',
|
||||||
|
'ΔRSS(KB)',
|
||||||
|
'ΔPeak(KB)',
|
||||||
|
'PeakRSS(KB)'
|
||||||
];
|
];
|
||||||
final dataRows = rows.map((r) {
|
final dataRows = rows.map((r) {
|
||||||
final readableName = nameMap[r['benchmark']] ?? r['benchmark'];
|
final readableName = nameMap[r['benchmark']] ?? r['benchmark'];
|
||||||
@@ -73,6 +94,6 @@ class MarkdownReport extends ReportGenerator {
|
|||||||
> `PeakRSS(KB)` – Max observed RSS memory (KB)
|
> `PeakRSS(KB)` – Max observed RSS memory (KB)
|
||||||
''';
|
''';
|
||||||
|
|
||||||
return '$legend\n\n${([headerLine, divider] + lines).join('\n')}' ;
|
return '$legend\n\n${([headerLine, divider] + lines).join('\n')}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,25 +7,46 @@ class PrettyReport extends ReportGenerator {
|
|||||||
/// List of columns to output in the pretty report.
|
/// List of columns to output in the pretty report.
|
||||||
@override
|
@override
|
||||||
final List<String> keys = [
|
final List<String> keys = [
|
||||||
'benchmark','chainCount','nestingDepth','mean_us','median_us','stddev_us',
|
'benchmark',
|
||||||
'min_us','max_us','trials','memory_diff_kb','delta_peak_kb','peak_rss_kb'
|
'chainCount',
|
||||||
|
'nestingDepth',
|
||||||
|
'mean_us',
|
||||||
|
'median_us',
|
||||||
|
'stddev_us',
|
||||||
|
'min_us',
|
||||||
|
'max_us',
|
||||||
|
'trials',
|
||||||
|
'memory_diff_kb',
|
||||||
|
'delta_peak_kb',
|
||||||
|
'peak_rss_kb'
|
||||||
];
|
];
|
||||||
|
|
||||||
/// Mappings from internal benchmark IDs to display names.
|
/// Mappings from internal benchmark IDs to display names.
|
||||||
static const nameMap = {
|
static const nameMap = {
|
||||||
'Universal_UniversalBenchmark.registerSingleton': 'RegisterSingleton',
|
'Universal_UniversalBenchmark.registerSingleton': 'RegisterSingleton',
|
||||||
'Universal_UniversalBenchmark.chainSingleton': 'ChainSingleton',
|
'Universal_UniversalBenchmark.chainSingleton': 'ChainSingleton',
|
||||||
'Universal_UniversalBenchmark.chainFactory': 'ChainFactory',
|
'Universal_UniversalBenchmark.chainFactory': 'ChainFactory',
|
||||||
'Universal_UniversalBenchmark.chainAsync': 'AsyncChain',
|
'Universal_UniversalBenchmark.chainAsync': 'AsyncChain',
|
||||||
'Universal_UniversalBenchmark.named': 'Named',
|
'Universal_UniversalBenchmark.named': 'Named',
|
||||||
'Universal_UniversalBenchmark.override': 'Override',
|
'Universal_UniversalBenchmark.override': 'Override',
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Renders the results as a header + tab-separated value table.
|
/// Renders the results as a header + tab-separated value table.
|
||||||
@override
|
@override
|
||||||
String render(List<Map<String, dynamic>> rows) {
|
String render(List<Map<String, dynamic>> rows) {
|
||||||
final headers = [
|
final headers = [
|
||||||
'Benchmark', 'Chain Count', 'Depth', 'Mean (us)', 'Median', 'Stddev', 'Min', 'Max', 'N', 'ΔRSS(KB)', 'ΔPeak(KB)', 'PeakRSS(KB)'
|
'Benchmark',
|
||||||
|
'Chain Count',
|
||||||
|
'Depth',
|
||||||
|
'Mean (us)',
|
||||||
|
'Median',
|
||||||
|
'Stddev',
|
||||||
|
'Min',
|
||||||
|
'Max',
|
||||||
|
'N',
|
||||||
|
'ΔRSS(KB)',
|
||||||
|
'ΔPeak(KB)',
|
||||||
|
'PeakRSS(KB)'
|
||||||
];
|
];
|
||||||
final header = headers.join('\t');
|
final header = headers.join('\t');
|
||||||
final lines = rows.map((r) {
|
final lines = rows.map((r) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
abstract class ReportGenerator {
|
abstract class ReportGenerator {
|
||||||
/// Renders the given [results] as a formatted string (table, markdown, csv, etc).
|
/// Renders the given [results] as a formatted string (table, markdown, csv, etc).
|
||||||
String render(List<Map<String, dynamic>> results);
|
String render(List<Map<String, dynamic>> results);
|
||||||
|
|
||||||
/// List of output columns/keys included in the export (or [] for auto/all).
|
/// List of output columns/keys included in the export (or [] for auto/all).
|
||||||
List<String> get keys;
|
List<String> get keys;
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,13 @@ import 'package:benchmark_di/benchmarks/universal_chain_async_benchmark.dart';
|
|||||||
class BenchmarkResult {
|
class BenchmarkResult {
|
||||||
/// List of timings for each run (in microseconds).
|
/// List of timings for each run (in microseconds).
|
||||||
final List<num> timings;
|
final List<num> timings;
|
||||||
|
|
||||||
/// Difference in memory (RSS, in KB) after running.
|
/// Difference in memory (RSS, in KB) after running.
|
||||||
final int memoryDiffKb;
|
final int memoryDiffKb;
|
||||||
|
|
||||||
/// Difference between peak RSS and initial RSS (in KB).
|
/// Difference between peak RSS and initial RSS (in KB).
|
||||||
final int deltaPeakKb;
|
final int deltaPeakKb;
|
||||||
|
|
||||||
/// Peak RSS memory observed (in KB).
|
/// Peak RSS memory observed (in KB).
|
||||||
final int peakRssKb;
|
final int peakRssKb;
|
||||||
BenchmarkResult({
|
BenchmarkResult({
|
||||||
@@ -19,6 +22,7 @@ class BenchmarkResult {
|
|||||||
required this.deltaPeakKb,
|
required this.deltaPeakKb,
|
||||||
required this.peakRssKb,
|
required this.peakRssKb,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Computes a BenchmarkResult instance from run timings and memory data.
|
/// Computes a BenchmarkResult instance from run timings and memory data.
|
||||||
factory BenchmarkResult.collect({
|
factory BenchmarkResult.collect({
|
||||||
required List<num> timings,
|
required List<num> timings,
|
||||||
@@ -64,7 +68,8 @@ class BenchmarkRunner {
|
|||||||
rssValues.add(ProcessInfo.currentRss);
|
rssValues.add(ProcessInfo.currentRss);
|
||||||
benchmark.teardown();
|
benchmark.teardown();
|
||||||
}
|
}
|
||||||
return BenchmarkResult.collect(timings: timings, rssValues: rssValues, memBefore: memBefore);
|
return BenchmarkResult.collect(
|
||||||
|
timings: timings, rssValues: rssValues, memBefore: memBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs an asynchronous benchmark ([UniversalChainAsyncBenchmark]) for a given number of [warmups] and [repeats].
|
/// Runs an asynchronous benchmark ([UniversalChainAsyncBenchmark]) for a given number of [warmups] and [repeats].
|
||||||
@@ -91,6 +96,7 @@ class BenchmarkRunner {
|
|||||||
rssValues.add(ProcessInfo.currentRss);
|
rssValues.add(ProcessInfo.currentRss);
|
||||||
await benchmark.teardown();
|
await benchmark.teardown();
|
||||||
}
|
}
|
||||||
return BenchmarkResult.collect(timings: timings, rssValues: rssValues, memBefore: memBefore);
|
return BenchmarkResult.collect(
|
||||||
|
timings: timings, rssValues: rssValues, memBefore: memBefore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,6 @@ import 'package:benchmark_di/scenarios/universal_service.dart';
|
|||||||
import 'package:cherrypick/cherrypick.dart';
|
import 'package:cherrypick/cherrypick.dart';
|
||||||
import 'di_adapter.dart';
|
import 'di_adapter.dart';
|
||||||
|
|
||||||
|
|
||||||
/// Test module that generates a chain of service bindings for benchmarking.
|
/// Test module that generates a chain of service bindings for benchmarking.
|
||||||
///
|
///
|
||||||
/// Configurable by chain count, nesting depth, binding mode, and scenario
|
/// Configurable by chain count, nesting depth, binding mode, and scenario
|
||||||
@@ -12,10 +11,13 @@ import 'di_adapter.dart';
|
|||||||
class UniversalChainModule extends Module {
|
class UniversalChainModule extends Module {
|
||||||
/// Number of chains to create.
|
/// Number of chains to create.
|
||||||
final int chainCount;
|
final int chainCount;
|
||||||
|
|
||||||
/// Depth of each chain.
|
/// Depth of each chain.
|
||||||
final int nestingDepth;
|
final int nestingDepth;
|
||||||
|
|
||||||
/// How modules are registered (factory/singleton/async).
|
/// How modules are registered (factory/singleton/async).
|
||||||
final UniversalBindingMode bindingMode;
|
final UniversalBindingMode bindingMode;
|
||||||
|
|
||||||
/// Which di scenario to generate (chained, named, etc).
|
/// Which di scenario to generate (chained, named, etc).
|
||||||
final UniversalScenario scenario;
|
final UniversalScenario scenario;
|
||||||
|
|
||||||
@@ -38,17 +40,18 @@ class UniversalChainModule extends Module {
|
|||||||
final prevDepName = '${chain}_${level - 1}';
|
final prevDepName = '${chain}_${level - 1}';
|
||||||
final depName = '${chain}_$level';
|
final depName = '${chain}_$level';
|
||||||
bind<UniversalService>()
|
bind<UniversalService>()
|
||||||
.toProvideAsync(() async {
|
.toProvideAsync(() async {
|
||||||
final prev = level > 1
|
final prev = level > 1
|
||||||
? await currentScope.resolveAsync<UniversalService>(named: prevDepName)
|
? await currentScope.resolveAsync<UniversalService>(
|
||||||
: null;
|
named: prevDepName)
|
||||||
return UniversalServiceImpl(
|
: null;
|
||||||
value: depName,
|
return UniversalServiceImpl(
|
||||||
dependency: prev,
|
value: depName,
|
||||||
);
|
dependency: prev,
|
||||||
})
|
);
|
||||||
.withName(depName)
|
})
|
||||||
.singleton();
|
.withName(depName)
|
||||||
|
.singleton();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -58,13 +61,18 @@ class UniversalChainModule extends Module {
|
|||||||
case UniversalScenario.register:
|
case UniversalScenario.register:
|
||||||
// Simple singleton registration.
|
// Simple singleton registration.
|
||||||
bind<UniversalService>()
|
bind<UniversalService>()
|
||||||
.toProvide(() => UniversalServiceImpl(value: 'reg', dependency: null))
|
.toProvide(
|
||||||
|
() => UniversalServiceImpl(value: 'reg', dependency: null))
|
||||||
.singleton();
|
.singleton();
|
||||||
break;
|
break;
|
||||||
case UniversalScenario.named:
|
case UniversalScenario.named:
|
||||||
// Named factory registration for two distinct objects.
|
// Named factory registration for two distinct objects.
|
||||||
bind<UniversalService>().toProvide(() => UniversalServiceImpl(value: 'impl1')).withName('impl1');
|
bind<UniversalService>()
|
||||||
bind<UniversalService>().toProvide(() => UniversalServiceImpl(value: 'impl2')).withName('impl2');
|
.toProvide(() => UniversalServiceImpl(value: 'impl1'))
|
||||||
|
.withName('impl1');
|
||||||
|
bind<UniversalService>()
|
||||||
|
.toProvide(() => UniversalServiceImpl(value: 'impl2'))
|
||||||
|
.withName('impl2');
|
||||||
break;
|
break;
|
||||||
case UniversalScenario.chain:
|
case UniversalScenario.chain:
|
||||||
// Chain of nested services, with dependency on previous level by name.
|
// Chain of nested services, with dependency on previous level by name.
|
||||||
@@ -79,7 +87,8 @@ class UniversalChainModule extends Module {
|
|||||||
bind<UniversalService>()
|
bind<UniversalService>()
|
||||||
.toProvide(() => UniversalServiceImpl(
|
.toProvide(() => UniversalServiceImpl(
|
||||||
value: depName,
|
value: depName,
|
||||||
dependency: currentScope.tryResolve<UniversalService>(named: prevDepName),
|
dependency: currentScope.tryResolve<UniversalService>(
|
||||||
|
named: prevDepName),
|
||||||
))
|
))
|
||||||
.withName(depName)
|
.withName(depName)
|
||||||
.singleton();
|
.singleton();
|
||||||
@@ -88,7 +97,8 @@ class UniversalChainModule extends Module {
|
|||||||
bind<UniversalService>()
|
bind<UniversalService>()
|
||||||
.toProvide(() => UniversalServiceImpl(
|
.toProvide(() => UniversalServiceImpl(
|
||||||
value: depName,
|
value: depName,
|
||||||
dependency: currentScope.tryResolve<UniversalService>(named: prevDepName),
|
dependency: currentScope.tryResolve<UniversalService>(
|
||||||
|
named: prevDepName),
|
||||||
))
|
))
|
||||||
.withName(depName);
|
.withName(depName);
|
||||||
break;
|
break;
|
||||||
@@ -96,7 +106,9 @@ class UniversalChainModule extends Module {
|
|||||||
bind<UniversalService>()
|
bind<UniversalService>()
|
||||||
.toProvideAsync(() async => UniversalServiceImpl(
|
.toProvideAsync(() async => UniversalServiceImpl(
|
||||||
value: depName,
|
value: depName,
|
||||||
dependency: await currentScope.resolveAsync<UniversalService>(named: prevDepName),
|
dependency:
|
||||||
|
await currentScope.resolveAsync<UniversalService>(
|
||||||
|
named: prevDepName),
|
||||||
))
|
))
|
||||||
.withName(depName)
|
.withName(depName)
|
||||||
.singleton();
|
.singleton();
|
||||||
@@ -107,14 +119,16 @@ class UniversalChainModule extends Module {
|
|||||||
// Регистрация алиаса без имени (на последний элемент цепочки)
|
// Регистрация алиаса без имени (на последний элемент цепочки)
|
||||||
final depName = '${chainCount}_$nestingDepth';
|
final depName = '${chainCount}_$nestingDepth';
|
||||||
bind<UniversalService>()
|
bind<UniversalService>()
|
||||||
.toProvide(() => currentScope.resolve<UniversalService>(named: depName))
|
.toProvide(
|
||||||
|
() => currentScope.resolve<UniversalService>(named: depName))
|
||||||
.singleton();
|
.singleton();
|
||||||
break;
|
break;
|
||||||
case UniversalScenario.override:
|
case UniversalScenario.override:
|
||||||
// handled at benchmark level, но алиас нужен прямо в этом scope!
|
// handled at benchmark level, но алиас нужен прямо в этом scope!
|
||||||
final depName = '${chainCount}_$nestingDepth';
|
final depName = '${chainCount}_$nestingDepth';
|
||||||
bind<UniversalService>()
|
bind<UniversalService>()
|
||||||
.toProvide(() => currentScope.resolve<UniversalService>(named: depName))
|
.toProvide(
|
||||||
|
() => currentScope.resolve<UniversalService>(named: depName))
|
||||||
.singleton();
|
.singleton();
|
||||||
break;
|
break;
|
||||||
case UniversalScenario.asyncChain:
|
case UniversalScenario.asyncChain:
|
||||||
@@ -124,7 +138,6 @@ class UniversalChainModule extends Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CherrypickDIAdapter extends DIAdapter<Scope> {
|
class CherrypickDIAdapter extends DIAdapter<Scope> {
|
||||||
Scope? _scope;
|
Scope? _scope;
|
||||||
final bool _isSubScope;
|
final bool _isSubScope;
|
||||||
@@ -158,7 +171,8 @@ class CherrypickDIAdapter extends DIAdapter<Scope> {
|
|||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
throw UnsupportedError('Scenario $scenario not supported by CherrypickDIAdapter');
|
throw UnsupportedError(
|
||||||
|
'Scenario $scenario not supported by CherrypickDIAdapter');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:benchmark_di/scenarios/universal_binding_mode.dart';
|
import 'package:benchmark_di/scenarios/universal_binding_mode.dart';
|
||||||
|
|
||||||
/// Универсальная абстракция для DI-адаптера с унифицированной функцией регистрации.
|
/// Универсальная абстракция для DI-адаптера с унифицированной функцией регистрации.
|
||||||
/// Теперь для каждого адаптера задаём строгий generic тип контейнера.
|
/// Теперь для каждого адаптера задаём строгий generic тип контейнера.
|
||||||
typedef Registration<TContainer> = void Function(TContainer);
|
typedef Registration<TContainer> = void Function(TContainer);
|
||||||
|
|||||||
@@ -80,9 +80,11 @@ class GetItAdapter extends DIAdapter<GetIt> {
|
|||||||
getIt.registerSingletonAsync<UniversalService>(
|
getIt.registerSingletonAsync<UniversalService>(
|
||||||
() async {
|
() async {
|
||||||
final prev = level > 1
|
final prev = level > 1
|
||||||
? await getIt.getAsync<UniversalService>(instanceName: prevDepName)
|
? await getIt.getAsync<UniversalService>(
|
||||||
|
instanceName: prevDepName)
|
||||||
: null;
|
: null;
|
||||||
return UniversalServiceImpl(value: depName, dependency: prev);
|
return UniversalServiceImpl(
|
||||||
|
value: depName, dependency: prev);
|
||||||
},
|
},
|
||||||
instanceName: depName,
|
instanceName: depName,
|
||||||
);
|
);
|
||||||
@@ -90,11 +92,16 @@ class GetItAdapter extends DIAdapter<GetIt> {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UniversalScenario.register:
|
case UniversalScenario.register:
|
||||||
getIt.registerSingleton<UniversalService>(UniversalServiceImpl(value: 'reg', dependency: null));
|
getIt.registerSingleton<UniversalService>(
|
||||||
|
UniversalServiceImpl(value: 'reg', dependency: null));
|
||||||
break;
|
break;
|
||||||
case UniversalScenario.named:
|
case UniversalScenario.named:
|
||||||
getIt.registerFactory<UniversalService>(() => UniversalServiceImpl(value: 'impl1'), instanceName: 'impl1');
|
getIt.registerFactory<UniversalService>(
|
||||||
getIt.registerFactory<UniversalService>(() => UniversalServiceImpl(value: 'impl2'), instanceName: 'impl2');
|
() => UniversalServiceImpl(value: 'impl1'),
|
||||||
|
instanceName: 'impl1');
|
||||||
|
getIt.registerFactory<UniversalService>(
|
||||||
|
() => UniversalServiceImpl(value: 'impl2'),
|
||||||
|
instanceName: 'impl2');
|
||||||
break;
|
break;
|
||||||
case UniversalScenario.chain:
|
case UniversalScenario.chain:
|
||||||
for (int chain = 1; chain <= chainCount; chain++) {
|
for (int chain = 1; chain <= chainCount; chain++) {
|
||||||
@@ -107,8 +114,8 @@ class GetItAdapter extends DIAdapter<GetIt> {
|
|||||||
UniversalServiceImpl(
|
UniversalServiceImpl(
|
||||||
value: depName,
|
value: depName,
|
||||||
dependency: level > 1
|
dependency: level > 1
|
||||||
? getIt<UniversalService>(instanceName: prevDepName)
|
? getIt<UniversalService>(instanceName: prevDepName)
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
instanceName: depName,
|
instanceName: depName,
|
||||||
);
|
);
|
||||||
@@ -129,8 +136,9 @@ class GetItAdapter extends DIAdapter<GetIt> {
|
|||||||
() async => UniversalServiceImpl(
|
() async => UniversalServiceImpl(
|
||||||
value: depName,
|
value: depName,
|
||||||
dependency: level > 1
|
dependency: level > 1
|
||||||
? await getIt.getAsync<UniversalService>(instanceName: prevDepName)
|
? await getIt.getAsync<UniversalService>(
|
||||||
: null,
|
instanceName: prevDepName)
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
instanceName: depName,
|
instanceName: depName,
|
||||||
);
|
);
|
||||||
@@ -143,7 +151,8 @@ class GetItAdapter extends DIAdapter<GetIt> {
|
|||||||
// handled at benchmark level
|
// handled at benchmark level
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (scenario == UniversalScenario.chain || scenario == UniversalScenario.override) {
|
if (scenario == UniversalScenario.chain ||
|
||||||
|
scenario == UniversalScenario.override) {
|
||||||
final depName = '${chainCount}_$nestingDepth';
|
final depName = '${chainCount}_$nestingDepth';
|
||||||
getIt.registerSingleton<UniversalService>(
|
getIt.registerSingleton<UniversalService>(
|
||||||
getIt<UniversalService>(instanceName: depName),
|
getIt<UniversalService>(instanceName: depName),
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ class RiverpodAdapter extends DIAdapter<Map<String, rp.ProviderBase<Object?>>> {
|
|||||||
_parent = parent;
|
_parent = parent;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void setupDependencies(void Function(Map<String, rp.ProviderBase<Object?>> container) registration) {
|
void setupDependencies(
|
||||||
|
void Function(Map<String, rp.ProviderBase<Object?>> container)
|
||||||
|
registration) {
|
||||||
_container ??= _parent == null
|
_container ??= _parent == null
|
||||||
? rp.ProviderContainer()
|
? rp.ProviderContainer()
|
||||||
: rp.ProviderContainer(parent: _parent);
|
: rp.ProviderContainer(parent: _parent);
|
||||||
@@ -76,7 +78,8 @@ class RiverpodAdapter extends DIAdapter<Map<String, rp.ProviderBase<Object?>>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Registration<Map<String, rp.ProviderBase<Object?>>> universalRegistration<S extends Enum>({
|
Registration<Map<String, rp.ProviderBase<Object?>>>
|
||||||
|
universalRegistration<S extends Enum>({
|
||||||
required S scenario,
|
required S scenario,
|
||||||
required int chainCount,
|
required int chainCount,
|
||||||
required int nestingDepth,
|
required int nestingDepth,
|
||||||
@@ -86,25 +89,34 @@ class RiverpodAdapter extends DIAdapter<Map<String, rp.ProviderBase<Object?>>> {
|
|||||||
return (providers) {
|
return (providers) {
|
||||||
switch (scenario) {
|
switch (scenario) {
|
||||||
case UniversalScenario.register:
|
case UniversalScenario.register:
|
||||||
providers['UniversalService'] = rp.Provider<UniversalService>((ref) => UniversalServiceImpl(value: 'reg', dependency: null));
|
providers['UniversalService'] = rp.Provider<UniversalService>(
|
||||||
|
(ref) => UniversalServiceImpl(value: 'reg', dependency: null));
|
||||||
break;
|
break;
|
||||||
case UniversalScenario.named:
|
case UniversalScenario.named:
|
||||||
providers['impl1'] = rp.Provider<UniversalService>((ref) => UniversalServiceImpl(value: 'impl1'));
|
providers['impl1'] = rp.Provider<UniversalService>(
|
||||||
providers['impl2'] = rp.Provider<UniversalService>((ref) => UniversalServiceImpl(value: 'impl2'));
|
(ref) => UniversalServiceImpl(value: 'impl1'));
|
||||||
|
providers['impl2'] = rp.Provider<UniversalService>(
|
||||||
|
(ref) => UniversalServiceImpl(value: 'impl2'));
|
||||||
break;
|
break;
|
||||||
case UniversalScenario.chain:
|
case UniversalScenario.chain:
|
||||||
for (int chain = 1; chain <= chainCount; chain++) {
|
for (int chain = 1; chain <= chainCount; chain++) {
|
||||||
for (int level = 1; level <= nestingDepth; level++) {
|
for (int level = 1; level <= nestingDepth; level++) {
|
||||||
final prevDepName = '${chain}_${level - 1}';
|
final prevDepName = '${chain}_${level - 1}';
|
||||||
final depName = '${chain}_$level';
|
final depName = '${chain}_$level';
|
||||||
providers[depName] = rp.Provider<UniversalService>((ref) => UniversalServiceImpl(
|
providers[depName] =
|
||||||
value: depName,
|
rp.Provider<UniversalService>((ref) => UniversalServiceImpl(
|
||||||
dependency: level > 1 ? ref.watch(providers[prevDepName] as rp.ProviderBase<UniversalService>) : null,
|
value: depName,
|
||||||
));
|
dependency: level > 1
|
||||||
|
? ref.watch(providers[prevDepName]
|
||||||
|
as rp.ProviderBase<UniversalService>)
|
||||||
|
: null,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final depName = '${chainCount}_$nestingDepth';
|
final depName = '${chainCount}_$nestingDepth';
|
||||||
providers['UniversalService'] = rp.Provider<UniversalService>((ref) => ref.watch(providers[depName] as rp.ProviderBase<UniversalService>));
|
providers['UniversalService'] = rp.Provider<UniversalService>(
|
||||||
|
(ref) => ref.watch(
|
||||||
|
providers[depName] as rp.ProviderBase<UniversalService>));
|
||||||
break;
|
break;
|
||||||
case UniversalScenario.override:
|
case UniversalScenario.override:
|
||||||
// handled at benchmark level
|
// handled at benchmark level
|
||||||
@@ -114,24 +126,31 @@ class RiverpodAdapter extends DIAdapter<Map<String, rp.ProviderBase<Object?>>> {
|
|||||||
for (int level = 1; level <= nestingDepth; level++) {
|
for (int level = 1; level <= nestingDepth; level++) {
|
||||||
final prevDepName = '${chain}_${level - 1}';
|
final prevDepName = '${chain}_${level - 1}';
|
||||||
final depName = '${chain}_$level';
|
final depName = '${chain}_$level';
|
||||||
providers[depName] = rp.FutureProvider<UniversalService>((ref) async {
|
providers[depName] =
|
||||||
|
rp.FutureProvider<UniversalService>((ref) async {
|
||||||
return UniversalServiceImpl(
|
return UniversalServiceImpl(
|
||||||
value: depName,
|
value: depName,
|
||||||
dependency: level > 1
|
dependency: level > 1
|
||||||
? await ref.watch((providers[prevDepName] as rp.FutureProvider<UniversalService>).future) as UniversalService?
|
? await ref.watch((providers[prevDepName]
|
||||||
|
as rp.FutureProvider<UniversalService>)
|
||||||
|
.future) as UniversalService?
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final depName = '${chainCount}_$nestingDepth';
|
final depName = '${chainCount}_$nestingDepth';
|
||||||
providers['UniversalService'] = rp.FutureProvider<UniversalService>((ref) async {
|
providers['UniversalService'] =
|
||||||
return await ref.watch((providers[depName] as rp.FutureProvider<UniversalService>).future);
|
rp.FutureProvider<UniversalService>((ref) async {
|
||||||
|
return await ref.watch(
|
||||||
|
(providers[depName] as rp.FutureProvider<UniversalService>)
|
||||||
|
.future);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
throw UnsupportedError('Scenario $scenario not supported by RiverpodAdapter');
|
throw UnsupportedError(
|
||||||
|
'Scenario $scenario not supported by RiverpodAdapter');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,16 @@
|
|||||||
enum UniversalScenario {
|
enum UniversalScenario {
|
||||||
/// Single registration.
|
/// Single registration.
|
||||||
register,
|
register,
|
||||||
|
|
||||||
/// Chain of dependencies.
|
/// Chain of dependencies.
|
||||||
chain,
|
chain,
|
||||||
|
|
||||||
/// Named registrations.
|
/// Named registrations.
|
||||||
named,
|
named,
|
||||||
|
|
||||||
/// Child-scope override scenario.
|
/// Child-scope override scenario.
|
||||||
override,
|
override,
|
||||||
|
|
||||||
/// Asynchronous chain scenario.
|
/// Asynchronous chain scenario.
|
||||||
asyncChain,
|
asyncChain,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/// Base interface for any universal service in the benchmarks.
|
/// Base interface for any universal service in the benchmarks.
|
||||||
///
|
///
|
||||||
/// Represents an object in the dependency chain with an identifiable value
|
/// Represents an object in the dependency chain with an identifiable value
|
||||||
@@ -6,6 +5,7 @@
|
|||||||
abstract class UniversalService {
|
abstract class UniversalService {
|
||||||
/// String ID for this service instance (e.g. chain/level info).
|
/// String ID for this service instance (e.g. chain/level info).
|
||||||
final String value;
|
final String value;
|
||||||
|
|
||||||
/// Optional reference to dependency service in the chain.
|
/// Optional reference to dependency service in the chain.
|
||||||
final UniversalService? dependency;
|
final UniversalService? dependency;
|
||||||
UniversalService({required this.value, this.dependency});
|
UniversalService({required this.value, this.dependency});
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ packages:
|
|||||||
path: "../cherrypick"
|
path: "../cherrypick"
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "3.0.0-dev.5"
|
version: "3.0.0-dev.9"
|
||||||
collection:
|
collection:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -1,3 +1,23 @@
|
|||||||
|
## 3.0.0-dev.10
|
||||||
|
|
||||||
|
- **DOCS**(pub): update homepage and documentation URLs in pubspec.yaml to new official site.
|
||||||
|
|
||||||
|
## 3.0.0-dev.9
|
||||||
|
|
||||||
|
- **DOCS**(readme): add talker_cherrypick_logger to Additional Modules section.
|
||||||
|
- **DOCS**(api): improve all DI core code documentation with English dartdoc and examples.
|
||||||
|
|
||||||
|
## 3.0.0-dev.8
|
||||||
|
|
||||||
|
- **REFACTOR**(tests): replace MockLogger with MockObserver in scope tests to align with updated observer API.
|
||||||
|
- **FIX**(doc): remove hide symbol.
|
||||||
|
- **FEAT**(core): add full DI lifecycle observability via onInstanceDisposed.
|
||||||
|
- **DOCS**(logging): update Logging section in README with modern Observer usage and Talker integration examples.
|
||||||
|
- **DOCS**(observer): improve documentation, translate all comments to English, add usage examples.
|
||||||
|
- **DOCS**(README): add section with overview table for additional modules.
|
||||||
|
- **DOCS**(README): refactor structure and improve clarity of advanced features.
|
||||||
|
- **DOCS**(README): add 'Hierarchical Subscopes' section and update structure for advanced features clarity.
|
||||||
|
|
||||||
## 3.0.0-dev.7
|
## 3.0.0-dev.7
|
||||||
|
|
||||||
> Note: This release has breaking changes.
|
> Note: This release has breaking changes.
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ It provides an easy-to-use system for registering, scoping, and resolving depend
|
|||||||
- [Binding](#binding)
|
- [Binding](#binding)
|
||||||
- [Module](#module)
|
- [Module](#module)
|
||||||
- [Scope](#scope)
|
- [Scope](#scope)
|
||||||
- [Automatic Resource Cleanup with Disposable](#automatic-resource-cleanup-with-disposable)
|
- [Disposable](#disposable)
|
||||||
- [Dependency Resolution API](#dependency-resolution-api)
|
- [Dependency Resolution API](#dependency-resolution-api)
|
||||||
- [Using Annotations & Code Generation](#using-annotations--code-generation)
|
- [Using Annotations & Code Generation](#using-annotations--code-generation)
|
||||||
- [Advanced Features](#advanced-features)
|
- [Advanced Features](#advanced-features)
|
||||||
@@ -24,6 +24,7 @@ It provides an easy-to-use system for registering, scoping, and resolving depend
|
|||||||
- [Example Application](#example-application)
|
- [Example Application](#example-application)
|
||||||
- [FAQ](#faq)
|
- [FAQ](#faq)
|
||||||
- [Documentation Links](#documentation-links)
|
- [Documentation Links](#documentation-links)
|
||||||
|
- [Additional Modules](#additional-modules)
|
||||||
- [Contributing](#contributing)
|
- [Contributing](#contributing)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
|
|
||||||
@@ -50,13 +51,14 @@ Add to your `pubspec.yaml`:
|
|||||||
```yaml
|
```yaml
|
||||||
dependencies:
|
dependencies:
|
||||||
cherrypick: ^<latest_version>
|
cherrypick: ^<latest_version>
|
||||||
```
|
````
|
||||||
|
|
||||||
Then run:
|
Then run:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
dart pub get
|
dart pub get
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
@@ -66,7 +68,6 @@ Here is a minimal example that registers and resolves a dependency:
|
|||||||
```dart
|
```dart
|
||||||
import 'package:cherrypick/cherrypick.dart';
|
import 'package:cherrypick/cherrypick.dart';
|
||||||
|
|
||||||
|
|
||||||
class AppModule extends Module {
|
class AppModule extends Module {
|
||||||
@override
|
@override
|
||||||
void builder(Scope currentScope) {
|
void builder(Scope currentScope) {
|
||||||
@@ -92,11 +93,11 @@ await CherryPick.closeRootScope();
|
|||||||
|
|
||||||
A **Binding** acts as a configuration for how to create or provide a particular dependency. Bindings support:
|
A **Binding** acts as a configuration for how to create or provide a particular dependency. Bindings support:
|
||||||
|
|
||||||
- Direct instance assignment (`toInstance()`, `toInstanceAsync()`)
|
* Direct instance assignment (`toInstance()`, `toInstanceAsync()`)
|
||||||
- Lazy providers (sync/async functions)
|
* Lazy providers (sync/async functions)
|
||||||
- Provider functions supporting dynamic parameters
|
* Provider functions supporting dynamic parameters
|
||||||
- Named instances for resolving by string key
|
* Named instances for resolving by string key
|
||||||
- Optional singleton lifecycle
|
* Optional singleton lifecycle
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
@@ -172,7 +173,7 @@ await CherryPick.closeRootScope();
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Automatic Resource Cleanup with Disposable
|
### Disposable
|
||||||
|
|
||||||
CherryPick can automatically clean up any dependency that implements the `Disposable` interface. This makes resource management (for controllers, streams, sockets, files, etc.) easy and reliable—especially when scopes or the app are shut down.
|
CherryPick can automatically clean up any dependency that implements the `Disposable` interface. This makes resource management (for controllers, streams, sockets, files, etc.) easy and reliable—especially when scopes or the app are shut down.
|
||||||
|
|
||||||
@@ -223,67 +224,17 @@ await CherryPick.closeRootScope(); // awaits async disposal
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Automatic resource management (`Disposable`, `dispose`)
|
## Dependency Resolution API
|
||||||
|
|
||||||
CherryPick automatically manages the lifecycle of any object registered via DI that implements the `Disposable` interface.
|
- `resolve<T>()` — Locates a dependency instance or throws if missing.
|
||||||
|
- `resolveAsync<T>()` — Async variant for dependencies requiring async binding.
|
||||||
|
- `tryResolve<T>()` — Returns `null` if not found (sync).
|
||||||
|
- `tryResolveAsync<T>()` — Returns `null` async if not found.
|
||||||
|
|
||||||
**Best practice:**
|
Supports:
|
||||||
Always finish your work with `await CherryPick.closeRootScope()` (for the root scope) or `await scope.closeSubScope('key')` (for subscopes).
|
- Synchronous and asynchronous dependencies
|
||||||
These methods will automatically await `dispose()` on all resolved objects (e.g., singletons) that implement `Disposable`, ensuring proper and complete resource cleanup—sync or async.
|
- Named dependencies
|
||||||
|
- Provider functions with and without runtime parameters
|
||||||
Manual `await scope.dispose()` may be useful if you manually manage custom scopes.
|
|
||||||
|
|
||||||
#### Example
|
|
||||||
|
|
||||||
```dart
|
|
||||||
class MyService implements Disposable {
|
|
||||||
@override
|
|
||||||
FutureOr<void> dispose() async {
|
|
||||||
// release resources, close streams, perform async shutdown, etc.
|
|
||||||
print('MyService disposed!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final scope = openRootScope();
|
|
||||||
scope.installModules([
|
|
||||||
ModuleImpl(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
final service = scope.resolve<MyService>();
|
|
||||||
|
|
||||||
// ... use service
|
|
||||||
|
|
||||||
// Recommended completion:
|
|
||||||
await CherryPick.closeRootScope(); // will print: MyService disposed!
|
|
||||||
|
|
||||||
// Or, to close and clean up a subscope and its resources:
|
|
||||||
await scope.closeSubScope('feature');
|
|
||||||
|
|
||||||
class ModuleImpl extends Module {
|
|
||||||
@override
|
|
||||||
void builder(Scope scope) {
|
|
||||||
bind<MyService>().toProvide(() => MyService()).singleton();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Working with Subscopes
|
|
||||||
|
|
||||||
```dart
|
|
||||||
// Open a named child scope (e.g., for a feature/module)
|
|
||||||
final subScope = rootScope.openSubScope('featureScope')
|
|
||||||
..installModules([FeatureModule()]);
|
|
||||||
|
|
||||||
// Resolve from subScope, with fallback to parents if missing
|
|
||||||
final dataBloc = await subScope.resolveAsync<DataBloc>();
|
|
||||||
```
|
|
||||||
|
|
||||||
### Fast Dependency Lookup (Performance Improvement)
|
|
||||||
|
|
||||||
> **Performance Note:**
|
|
||||||
> **Starting from version 3.0.0**, CherryPick uses a Map-based resolver index for dependency lookup. This means calls to `resolve<T>()` and related methods are now O(1) operations, regardless of the number of modules or bindings in your scope. Previously, the library had to iterate over all modules and bindings to locate the requested dependency, which could impact performance as your project grew.
|
|
||||||
>
|
|
||||||
> This optimization is internal and does not change any library APIs or usage patterns, but it significantly improves resolution speed in larger applications.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -337,7 +288,7 @@ class ProfilePage with _\$ProfilePage {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- After running build_runner, the mixin `_ | |||||||