mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-24 13:47:24 +00:00
Compare commits
49 Commits
cherrypick
...
cherrypick
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cbcce5b38 | ||
|
|
264c4bbb88 | ||
|
|
cbb5dcc3a0 | ||
|
|
d281c18a75 | ||
|
|
8ef12e990f | ||
|
|
5c57370755 | ||
|
|
8711dc83d0 | ||
|
|
043737e2c9 | ||
|
|
ed65e3c23d | ||
|
|
a897c1b31b | ||
|
|
dd9c3faa62 | ||
|
|
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
|
||||||
270
CHANGELOG.md
270
CHANGELOG.md
@@ -3,6 +3,276 @@
|
|||||||
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-22
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Packages with breaking changes:
|
||||||
|
|
||||||
|
- There are no breaking changes in this release.
|
||||||
|
|
||||||
|
Packages with other changes:
|
||||||
|
|
||||||
|
- [`cherrypick_annotations` - `v1.1.2-dev.2`](#cherrypick_annotations---v112-dev2)
|
||||||
|
- [`cherrypick_generator` - `v2.0.0-dev.2`](#cherrypick_generator---v200-dev2)
|
||||||
|
|
||||||
|
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_generator` - `v2.0.0-dev.2`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### `cherrypick_annotations` - `v1.1.2-dev.2`
|
||||||
|
|
||||||
|
- **DOCS**(annotations): improve API documentation and usage example.
|
||||||
|
|
||||||
|
|
||||||
|
## 2025-08-19
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Packages with breaking changes:
|
||||||
|
|
||||||
|
- There are no breaking changes in this release.
|
||||||
|
|
||||||
|
Packages with other changes:
|
||||||
|
|
||||||
|
- [`cherrypick` - `v3.0.0-dev.12`](#cherrypick---v300-dev12)
|
||||||
|
- [`cherrypick_flutter` - `v1.1.3-dev.12`](#cherrypick_flutter---v113-dev12)
|
||||||
|
- [`talker_cherrypick_logger` - `v1.1.0-dev.7`](#talker_cherrypick_logger---v110-dev7)
|
||||||
|
|
||||||
|
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.12`
|
||||||
|
- `talker_cherrypick_logger` - `v1.1.0-dev.7`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### `cherrypick` - `v3.0.0-dev.12`
|
||||||
|
|
||||||
|
- **FIX**(scope): prevent concurrent modification in dispose().
|
||||||
|
- **FIX**(binding): fix unterminated string literal and syntax issues in binding.dart.
|
||||||
|
|
||||||
|
|
||||||
|
## 2025-08-19
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Packages with breaking changes:
|
||||||
|
|
||||||
|
- There are no breaking changes in this release.
|
||||||
|
|
||||||
|
Packages with other changes:
|
||||||
|
|
||||||
|
- [`cherrypick` - `v3.0.0-dev.11`](#cherrypick---v300-dev11)
|
||||||
|
- [`cherrypick_flutter` - `v1.1.3-dev.11`](#cherrypick_flutter---v113-dev11)
|
||||||
|
- [`talker_cherrypick_logger` - `v1.1.0-dev.6`](#talker_cherrypick_logger---v110-dev6)
|
||||||
|
|
||||||
|
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.11`
|
||||||
|
- `talker_cherrypick_logger` - `v1.1.0-dev.6`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### `cherrypick` - `v3.0.0-dev.11`
|
||||||
|
|
||||||
|
- **FIX**(scope): prevent concurrent modification in dispose().
|
||||||
|
- **FIX**(binding): fix unterminated string literal and syntax issues in binding.dart.
|
||||||
|
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
# Comparative DI Benchmark Report: cherrypick vs get_it vs riverpod
|
# Comparative DI Benchmark Report: cherrypick vs get_it vs riverpod vs kiwi
|
||||||
|
|
||||||
|
## Benchmark Parameters
|
||||||
|
|
||||||
|
- chainCount = 100
|
||||||
|
- nestingDepth = 100
|
||||||
|
- repeat = 5
|
||||||
|
- warmup = 2
|
||||||
|
|
||||||
## Benchmark Scenarios
|
## Benchmark Scenarios
|
||||||
|
|
||||||
@@ -11,41 +18,49 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Comparative Table: chainCount=10, nestingDepth=10 (Mean, PeakRSS)
|
## Comparative Table: chainCount=100, nestingDepth=100, repeat=5, warmup=2 (Mean time, µs)
|
||||||
|
|
||||||
| Scenario | cherrypick Mean (us) | cherrypick PeakRSS | get_it Mean (us) | get_it PeakRSS | riverpod Mean (us) | riverpod PeakRSS |
|
| Scenario | cherrypick | get_it | riverpod | kiwi | yx_scope |
|
||||||
|--------------------|---------------------:|-------------------:|-----------------:|---------------:|-------------------:|-----------------:|
|
|------------------|------------|--------|----------|-------|----------|
|
||||||
| RegisterSingleton | 13.00 | 273104 | 8.40 | 261872 | 9.80 | 268512 |
|
| chainSingleton | 20.6 | 14.8 | 275.2 | 47.0 | 82.8 |
|
||||||
| ChainSingleton | 13.80 | 271072 | 2.00 | 262000 | 33.60 | 268784 |
|
| chainFactory | 90.6 | 71.6 | 357.0 | 46.2 | 79.6 |
|
||||||
| ChainFactory | 5.00 | 299216 | 4.00 | 297136 | 22.80 | 271296 |
|
| register | 82.6 | 10.2 | 252.6 | 43.6 | 224.0 |
|
||||||
| AsyncChain | 28.60 | 290640 | 24.60 | 342976 | 78.20 | 285920 |
|
| named | 18.4 | 9.4 | 12.2 | 10.2 | 10.8 |
|
||||||
| Named | 2.20 | 297008 | 0.20 | 449824 | 6.20 | 281136 |
|
| override | 170.6 | 11.2 | 301.4 | 51.4 | 146.4 |
|
||||||
| Override | 7.00 | 297024 | 0.00 | 449824 | 30.20 | 281152 |
|
| chainAsync | 493.8 | 34.0 | 5,039.0 | – | 87.2 |
|
||||||
|
|
||||||
## Maximum Load: chainCount=100, nestingDepth=100 (Mean, PeakRSS)
|
|
||||||
|
|
||||||
| Scenario | cherrypick Mean (us) | cherrypick PeakRSS | get_it Mean (us) | get_it PeakRSS | riverpod Mean (us) | riverpod PeakRSS |
|
## Peak Memory Usage (Peak RSS, Kb)
|
||||||
|--------------------|---------------------:|-------------------:|-----------------:|---------------:|-------------------:|-----------------:|
|
|
||||||
| RegisterSingleton | 4.00 | 271072 | 1.00 | 262000 | 2.00 | 268688 |
|
| Scenario | cherrypick | get_it | riverpod | kiwi | yx_scope |
|
||||||
| ChainSingleton | 76.60 | 303312 | 2.00 | 297136 | 221.80 | 270784 |
|
|------------------|------------|--------|----------|--------|----------|
|
||||||
| ChainFactory | 80.00 | 293952 | 39.20 | 342720 | 195.80 | 308640 |
|
| chainSingleton | 338,224 | 326,752| 301,856 | 195,520| 320,928 |
|
||||||
| AsyncChain | 251.40 | 297008 | 18.20 | 450640 | 748.80 | 285968 |
|
| chainFactory | 339,040 | 335,712| 304,832 | 319,952| 318,688 |
|
||||||
| Named | 2.20 | 297008 | 0.00 | 449824 | 1.00 | 281136 |
|
| register | 333,760 | 334,208| 300,368 | 327,968| 326,736 |
|
||||||
| Override | 104.80 | 301632 | 2.20 | 477344 | 120.80 | 294752 |
|
| named | 241,040 | 229,632| 280,144 | 271,872| 266,352 |
|
||||||
|
| override | 356,912 | 331,456| 329,808 | 369,104| 304,416 |
|
||||||
|
| chainAsync | 311,616 | 434,592| 301,168 | – | 328,912 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Analysis
|
## Analysis
|
||||||
|
|
||||||
- **get_it** is the absolute leader in all scenarios, especially under deep/nested chains and async.
|
- **get_it** remains the clear leader for both speed and memory usage (lowest latency across most scenarios; excellent memory efficiency even on deep chains).
|
||||||
- **cherrypick** is highly competitive and much faster than riverpod on any complex graph.
|
- **kiwi** shows the lowest memory footprint in chainSingleton, but is unavailable for async chains.
|
||||||
- **riverpod** is only suitable for small/simple DI graphs due to major slowdowns with depth, async, or override.
|
- **yx_scope** demonstrates highly stable performance for both sync and async chains, often at the cost of higher memory usage, especially in the register/override scenarios.
|
||||||
|
- **cherrypick** comfortably beats riverpod, but is outperformed by get_it/kiwi/yx_scope, especially on async and heavy nested chains. It uses a bit less memory than yx_scope and kiwi, but can spike in memory/latency for override.
|
||||||
|
- **riverpod** is unsuitable for deep or async chains—latency and memory usage grow rapidly.
|
||||||
|
- **Peak memory (RSS):** usually around 320–340 MB for all DI; riverpod/kiwi occasionally drops below 300MB. named/factory scenarios use much less.
|
||||||
|
- **Stability:** yx_scope and get_it have the lowest latency spikes; cherrypick can show peaks on override/async; riverpod is least stable on async (stddev/mean much worse).
|
||||||
|
|
||||||
### Recommendations
|
### Recommendations
|
||||||
- Use **get_it** for performance-critical and deeply nested graphs.
|
|
||||||
- Use **cherrypick** for scalable/testable apps if a small speed loss is acceptable.
|
- **get_it** (and often **kiwi**, if you don't need async): best for ultra-fast deep graphs and minimum peak memory.
|
||||||
- Use **riverpod** only if you rely on Flutter integration and your DI chains are simple.
|
- **yx_scope**: best blend of performance and async stability; perfect for production mixed DI.
|
||||||
|
- **cherrypick**: great for modular/testable architectures, unless absolute peak is needed; lower memory than yx_scope in some scenarios.
|
||||||
|
- **riverpod**: only for shallow DI or UI wiring in Flutter.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
_Last updated: August 8, 2025._
|
_Last updated: August 20, 2025._
|
||||||
|
_Please see scenario source for details._
|
||||||
|
|||||||
@@ -1,51 +1,63 @@
|
|||||||
# Сравнительный отчет DI-бенчмарка: cherrypick vs get_it vs riverpod
|
# Сравнительный отчет DI-бенчмарка: cherrypick vs get_it vs riverpod vs kiwi
|
||||||
|
|
||||||
|
## Параметры запуска:
|
||||||
|
- chainCount = 100
|
||||||
|
- nestingDepth = 100
|
||||||
|
- repeat = 5
|
||||||
|
- warmup = 2
|
||||||
|
|
||||||
## Описание сценариев
|
## Описание сценариев
|
||||||
|
|
||||||
1. **RegisterSingleton** — регистрация и получение объекта-синглтона (базовая скорость DI).
|
1. **RegisterSingleton** — регистрация и получение singleton (базовая скорость DI).
|
||||||
2. **ChainSingleton** — цепочка зависимостей A → B → ... → N (singleton). Глубокий singleton-резолвинг.
|
2. **ChainSingleton** — цепочка зависимостей A → B → ... → N (singleton). Глубокий singleton-резолвинг.
|
||||||
3. **ChainFactory** — все элементы цепочки — фабрики. Stateless построение графа.
|
3. **ChainFactory** — все элементы цепочки — factory. Stateless построение графа.
|
||||||
4. **AsyncChain** — асинхронная цепочка (async factory). Тестирует async/await граф.
|
4. **AsyncChain** — асинхронная цепочка (async factory). Тест async/await графа.
|
||||||
5. **Named** — регистрация двух биндингов с именами, разрешение по имени.
|
5. **Named** — регистрация двух биндингов с именами, разрешение по имени.
|
||||||
6. **Override** — регистрация биндинга/цепочки в дочернем scope. Проверка override/scoping.
|
6. **Override** — регистрация биндинга/цепочки в дочернем scope.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Сводная таблица: chainCount=10, nestingDepth=10 (Mean, PeakRSS)
|
## Сравнительная таблица: chainCount=100, nestingDepth=100, repeat=5, warmup=2 (среднее время, мкс)
|
||||||
|
|
||||||
| Сценарий | cherrypick Mean (мкс) | cherrypick PeakRSS | get_it Mean (мкс) | get_it PeakRSS | riverpod Mean (мкс) | riverpod PeakRSS |
|
| Сценарий | cherrypick | get_it | riverpod | kiwi | yx_scope |
|
||||||
|--------------------|----------------------:|-------------------:|------------------:|---------------:|--------------------:|-----------------:|
|
|------------------|------------|--------|----------|-------|----------|
|
||||||
| RegisterSingleton | 13.00 | 273104 | 8.40 | 261872 | 9.80 | 268512 |
|
| chainSingleton | 20.6 | 14.8 | 275.2 | 47.0 | 82.8 |
|
||||||
| ChainSingleton | 13.80 | 271072 | 2.00 | 262000 | 33.60 | 268784 |
|
| chainFactory | 90.6 | 71.6 | 357.0 | 46.2 | 79.6 |
|
||||||
| ChainFactory | 5.00 | 299216 | 4.00 | 297136 | 22.80 | 271296 |
|
| register | 82.6 | 10.2 | 252.6 | 43.6 | 224.0 |
|
||||||
| AsyncChain | 28.60 | 290640 | 24.60 | 342976 | 78.20 | 285920 |
|
| named | 18.4 | 9.4 | 12.2 | 10.2 | 10.8 |
|
||||||
| Named | 2.20 | 297008 | 0.20 | 449824 | 6.20 | 281136 |
|
| override | 170.6 | 11.2 | 301.4 | 51.4 | 146.4 |
|
||||||
| Override | 7.00 | 297024 | 0.00 | 449824 | 30.20 | 281152 |
|
| chainAsync | 493.8 | 34.0 | 5,039.0 | – | 87.2 |
|
||||||
|
|
||||||
## Максимальная нагрузка: chainCount=100, nestingDepth=100 (Mean, PeakRSS)
|
|
||||||
|
|
||||||
| Сценарий | cherrypick Mean (мкс) | cherrypick PeakRSS | get_it Mean (мкс) | get_it PeakRSS | riverpod Mean (мкс) | riverpod PeakRSS |
|
## Пиковое потребление памяти (Peak RSS, Кб)
|
||||||
|--------------------|----------------------:|-------------------:|------------------:|---------------:|--------------------:|-----------------:|
|
|
||||||
| RegisterSingleton | 4.00 | 271072 | 1.00 | 262000 | 2.00 | 268688 |
|
| Сценарий | cherrypick | get_it | riverpod | kiwi | yx_scope |
|
||||||
| ChainSingleton | 76.60 | 303312 | 2.00 | 297136 | 221.80 | 270784 |
|
|------------------|------------|--------|----------|--------|----------|
|
||||||
| ChainFactory | 80.00 | 293952 | 39.20 | 342720 | 195.80 | 308640 |
|
| chainSingleton | 338,224 | 326,752| 301,856 | 195,520| 320,928 |
|
||||||
| AsyncChain | 251.40 | 297008 | 18.20 | 450640 | 748.80 | 285968 |
|
| chainFactory | 339,040 | 335,712| 304,832 | 319,952| 318,688 |
|
||||||
| Named | 2.20 | 297008 | 0.00 | 449824 | 1.00 | 281136 |
|
| register | 333,760 | 334,208| 300,368 | 327,968| 326,736 |
|
||||||
| Override | 104.80 | 301632 | 2.20 | 477344 | 120.80 | 294752 |
|
| named | 241,040 | 229,632| 280,144 | 271,872| 266,352 |
|
||||||
|
| override | 356,912 | 331,456| 329,808 | 369,104| 304,416 |
|
||||||
|
| chainAsync | 311,616 | 434,592| 301,168 | – | 328,912 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Краткий анализ и рекомендации
|
## Краткий анализ и рекомендации
|
||||||
|
|
||||||
- **get_it** всегда лидер, особенно на глубине/асинхронных графах.
|
- **get_it** — абсолютный лидер по скорости и памяти на всех графах (минимальная задержка, небольшой peak RSS в любых цепочках).
|
||||||
- **cherrypick** заметно быстрее riverpod на сложных сценариях, опережая его в разы.
|
- **kiwi** — минимальное потребление памяти в chainSingleton/Factory, но не для асинхронности.
|
||||||
- **riverpod** подходит только для простых/небольших графов — при росте глубины или async/override резко проигрывает по скорости.
|
- **yx_scope** — очень ровная производительность даже на сложных async/sync-цепях, иногда с пиком в памяти на override/register, но задержки всегда минимальны.
|
||||||
|
- **cherrypick** — стабильнее riverpod, но ощутимо уступает top-3 по латентности на длинных/async-графах; по памяти лучше yx_scope для override/named.
|
||||||
|
- **riverpod** — непригоден для глубоких/async-графов: память и время растут очень сильно.
|
||||||
|
- **Пиковое потребление памяти**: большинство DI держится в районе 320–340 Мб (большие цепи), на мелких named/factory — крайне мало.
|
||||||
|
- **Стабильность**: yx_scope и get_it показывают наименьшие скачки времени; у cherrypick иногда всплески на override/async, у riverpod — на async графе stddev почти равен mean!
|
||||||
|
|
||||||
### Рекомендации
|
### Рекомендации
|
||||||
- Используйте **get_it** для критичных к скорости приложений/сложных графов зависимостей.
|
- Используйте **get_it** (или **kiwi**, если не нужен async) для максимальной производительности и минимального пикового использования памяти.
|
||||||
- Выбирайте **cherrypick** для масштабируемых, тестируемых архитектур, если микросекундная разница не критична.
|
- **yx_scope** — идеально для production-графов с миксом sync/async.
|
||||||
- **riverpod** уместен только для реактивного UI или простых графов DI.
|
- **cherrypick** — хорошо для модульных и тестируемых приложений, если не требуется абсолютная “микросекундная” производительность.
|
||||||
|
- **riverpod** — только если граф плоский или нужно DI только для UI во Flutter.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
_Обновлено: 8 августа 2025_
|
_Обновлено: 20 августа 2025._
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ import 'package:benchmark_di/cli/benchmark_cli.dart';
|
|||||||
|
|
||||||
Future<void> main(List<String> args) async {
|
Future<void> main(List<String> args) async {
|
||||||
await BenchmarkCliRunner().run(args);
|
await BenchmarkCliRunner().run(args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:benchmark_di/cli/report/markdown_report.dart';
|
import 'package:benchmark_di/cli/report/markdown_report.dart';
|
||||||
|
import 'package:benchmark_di/di_adapters/yx_scope_adapter.dart';
|
||||||
|
import 'package:benchmark_di/di_adapters/yx_scope_universal_container.dart';
|
||||||
import 'package:benchmark_di/scenarios/universal_scenario.dart';
|
import 'package:benchmark_di/scenarios/universal_scenario.dart';
|
||||||
import 'package:cherrypick/cherrypick.dart';
|
import 'package:cherrypick/cherrypick.dart';
|
||||||
import 'package:get_it/get_it.dart';
|
import 'package:get_it/get_it.dart';
|
||||||
@@ -16,6 +18,8 @@ import 'package:benchmark_di/benchmarks/universal_chain_async_benchmark.dart';
|
|||||||
import 'package:benchmark_di/di_adapters/cherrypick_adapter.dart';
|
import 'package:benchmark_di/di_adapters/cherrypick_adapter.dart';
|
||||||
import 'package:benchmark_di/di_adapters/get_it_adapter.dart';
|
import 'package:benchmark_di/di_adapters/get_it_adapter.dart';
|
||||||
import 'package:benchmark_di/di_adapters/riverpod_adapter.dart';
|
import 'package:benchmark_di/di_adapters/riverpod_adapter.dart';
|
||||||
|
import 'package:benchmark_di/di_adapters/kiwi_adapter.dart';
|
||||||
|
import 'package:kiwi/kiwi.dart';
|
||||||
|
|
||||||
/// Command-line interface (CLI) runner for benchmarks.
|
/// Command-line interface (CLI) runner for benchmarks.
|
||||||
///
|
///
|
||||||
@@ -36,8 +40,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 +52,41 @@ 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(
|
||||||
|
benchmark: benchSync,
|
||||||
|
warmups: config.warmups,
|
||||||
|
repeats: config.repeats,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (config.di == 'kiwi') {
|
||||||
|
final di = KiwiAdapter();
|
||||||
|
if (scenario == UniversalScenario.asyncChain) {
|
||||||
|
// UnsupportedError будет выброшен адаптером, но если дойдёт — вызывать async benchmark
|
||||||
|
final benchAsync = UniversalChainAsyncBenchmark<KiwiContainer>(
|
||||||
|
di,
|
||||||
|
chainCount: c,
|
||||||
|
nestingDepth: d,
|
||||||
|
mode: mode,
|
||||||
|
);
|
||||||
|
benchResult = await BenchmarkRunner.runAsync(
|
||||||
|
benchmark: benchAsync,
|
||||||
|
warmups: config.warmups,
|
||||||
|
repeats: config.repeats,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
final benchSync = UniversalChainBenchmark<KiwiContainer>(
|
||||||
|
di,
|
||||||
|
chainCount: c,
|
||||||
|
nestingDepth: d,
|
||||||
|
mode: mode,
|
||||||
|
scenario: scenario,
|
||||||
);
|
);
|
||||||
benchResult = await BenchmarkRunner.runSync(
|
benchResult = await BenchmarkRunner.runSync(
|
||||||
benchmark: benchSync,
|
benchmark: benchSync,
|
||||||
@@ -57,8 +97,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 +110,41 @@ 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(
|
||||||
|
benchmark: benchSync,
|
||||||
|
warmups: config.warmups,
|
||||||
|
repeats: config.repeats,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (config.di == 'yx_scope') {
|
||||||
|
final di = YxScopeAdapter();
|
||||||
|
if (scenario == UniversalScenario.asyncChain) {
|
||||||
|
final benchAsync = UniversalChainAsyncBenchmark<UniversalYxScopeContainer>(
|
||||||
|
di,
|
||||||
|
chainCount: c,
|
||||||
|
nestingDepth: d,
|
||||||
|
mode: mode,
|
||||||
|
);
|
||||||
|
benchResult = await BenchmarkRunner.runAsync(
|
||||||
|
benchmark: benchAsync,
|
||||||
|
warmups: config.warmups,
|
||||||
|
repeats: config.repeats,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
final benchSync = UniversalChainBenchmark<UniversalYxScopeContainer>(
|
||||||
|
di,
|
||||||
|
chainCount: c,
|
||||||
|
nestingDepth: d,
|
||||||
|
mode: mode,
|
||||||
|
scenario: scenario,
|
||||||
);
|
);
|
||||||
benchResult = await BenchmarkRunner.runSync(
|
benchResult = await BenchmarkRunner.runSync(
|
||||||
benchmark: benchSync,
|
benchmark: benchSync,
|
||||||
@@ -78,8 +155,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 +167,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 +187,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 +216,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) {
|
||||||
@@ -127,4 +143,4 @@ BenchmarkCliConfig parseBenchmarkCli(List<String> args) {
|
|||||||
format: result['format'] as String,
|
format: result['format'] as String,
|
||||||
di: result['di'] as String? ?? 'cherrypick',
|
di: result['di'] as String? ?? 'cherrypick',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,9 +5,10 @@ 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) {
|
||||||
return '[\n${rows.map((r) => ' $r').join(',\n')}\n]';
|
return '[\n${rows.map((r) => ' $r').join(',\n')}\n]';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -170,9 +184,9 @@ class CherrypickDIAdapter extends DIAdapter<Scope> {
|
|||||||
_scope!.resolveAsync<T>(named: named);
|
_scope!.resolveAsync<T>(named: named);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void teardown() {
|
Future<void> teardown() async {
|
||||||
if (!_isSubScope) {
|
if (!_isSubScope) {
|
||||||
CherryPick.closeRootScope();
|
await CherryPick.closeRootScope();
|
||||||
_scope = null;
|
_scope = null;
|
||||||
}
|
}
|
||||||
// SubScope teardown не требуется
|
// SubScope teardown не требуется
|
||||||
|
|||||||
@@ -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),
|
||||||
|
|||||||
129
benchmark_di/lib/di_adapters/kiwi_adapter.dart
Normal file
129
benchmark_di/lib/di_adapters/kiwi_adapter.dart
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
import 'package:benchmark_di/scenarios/universal_binding_mode.dart';
|
||||||
|
import 'package:benchmark_di/scenarios/universal_scenario.dart';
|
||||||
|
import 'package:benchmark_di/scenarios/universal_service.dart';
|
||||||
|
import 'package:kiwi/kiwi.dart';
|
||||||
|
import 'di_adapter.dart';
|
||||||
|
|
||||||
|
/// DIAdapter-для KiwiContainer с поддержкой universal benchmark сценариев.
|
||||||
|
class KiwiAdapter extends DIAdapter<KiwiContainer> {
|
||||||
|
late KiwiContainer _container;
|
||||||
|
// ignore: unused_field
|
||||||
|
final bool _isSubScope;
|
||||||
|
|
||||||
|
KiwiAdapter({KiwiContainer? container, bool isSubScope = false})
|
||||||
|
: _isSubScope = isSubScope {
|
||||||
|
_container = container ?? KiwiContainer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void setupDependencies(void Function(KiwiContainer container) registration) {
|
||||||
|
registration(_container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Registration<KiwiContainer> universalRegistration<S extends Enum>({
|
||||||
|
required S scenario,
|
||||||
|
required int chainCount,
|
||||||
|
required int nestingDepth,
|
||||||
|
required UniversalBindingMode bindingMode,
|
||||||
|
}) {
|
||||||
|
if (scenario is UniversalScenario) {
|
||||||
|
if (scenario == UniversalScenario.asyncChain ||
|
||||||
|
bindingMode == UniversalBindingMode.asyncStrategy) {
|
||||||
|
throw UnsupportedError('Kiwi does not support async dependencies or async binding scenarios.');
|
||||||
|
}
|
||||||
|
return (container) {
|
||||||
|
switch (scenario) {
|
||||||
|
case UniversalScenario.asyncChain:
|
||||||
|
break;
|
||||||
|
case UniversalScenario.register:
|
||||||
|
container.registerSingleton<UniversalService>(
|
||||||
|
(c) => UniversalServiceImpl(value: 'reg', dependency: null),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case UniversalScenario.named:
|
||||||
|
container.registerFactory<UniversalService>(
|
||||||
|
(c) => UniversalServiceImpl(value: 'impl1'), name: 'impl1');
|
||||||
|
container.registerFactory<UniversalService>(
|
||||||
|
(c) => UniversalServiceImpl(value: 'impl2'), name: 'impl2');
|
||||||
|
break;
|
||||||
|
case UniversalScenario.chain:
|
||||||
|
for (int chain = 1; chain <= chainCount; chain++) {
|
||||||
|
for (int level = 1; level <= nestingDepth; level++) {
|
||||||
|
final prevDepName = '${chain}_${level - 1}';
|
||||||
|
final depName = '${chain}_$level';
|
||||||
|
switch (bindingMode) {
|
||||||
|
case UniversalBindingMode.singletonStrategy:
|
||||||
|
container.registerSingleton<UniversalService>(
|
||||||
|
(c) => UniversalServiceImpl(
|
||||||
|
value: depName,
|
||||||
|
dependency: level > 1
|
||||||
|
? c.resolve<UniversalService>(prevDepName)
|
||||||
|
: null),
|
||||||
|
name: depName);
|
||||||
|
break;
|
||||||
|
case UniversalBindingMode.factoryStrategy:
|
||||||
|
container.registerFactory<UniversalService>(
|
||||||
|
(c) => UniversalServiceImpl(
|
||||||
|
value: depName,
|
||||||
|
dependency: level > 1
|
||||||
|
? c.resolve<UniversalService>(prevDepName)
|
||||||
|
: null),
|
||||||
|
name: depName);
|
||||||
|
break;
|
||||||
|
case UniversalBindingMode.asyncStrategy:
|
||||||
|
// Не поддерживается
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final depName = '${chainCount}_$nestingDepth';
|
||||||
|
container.registerSingleton<UniversalService>(
|
||||||
|
(c) => c.resolve<UniversalService>(depName));
|
||||||
|
break;
|
||||||
|
case UniversalScenario.override:
|
||||||
|
final depName = '${chainCount}_$nestingDepth';
|
||||||
|
container.registerSingleton<UniversalService>(
|
||||||
|
(c) => c.resolve<UniversalService>(depName));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw UnsupportedError('Scenario $scenario not supported by KiwiAdapter');
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
T resolve<T extends Object>({String? named}) {
|
||||||
|
// Для asyncChain нужен resolve<Future<T>>
|
||||||
|
if (T.toString().startsWith('Future<')) {
|
||||||
|
return _container.resolve<T>(named);
|
||||||
|
} else {
|
||||||
|
return _container.resolve<T>(named);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<T> resolveAsync<T extends Object>({String? named}) async {
|
||||||
|
if (T.toString().startsWith('Future<')) {
|
||||||
|
// resolve<Future<T>>, unwrap result
|
||||||
|
return Future.value(_container.resolve<T>(named));
|
||||||
|
} else {
|
||||||
|
// Для совместимости с chain/override
|
||||||
|
return Future.value(_container.resolve<T>(named));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void teardown() {
|
||||||
|
_container.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
KiwiAdapter openSubScope(String name) {
|
||||||
|
// Возвращаем новый scoped контейнер (отдельный). Наследование не реализовано.
|
||||||
|
return KiwiAdapter(container: KiwiContainer.scoped(), isSubScope: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> waitForAsyncReady() async {}
|
||||||
|
}
|
||||||
@@ -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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
126
benchmark_di/lib/di_adapters/yx_scope_adapter.dart
Normal file
126
benchmark_di/lib/di_adapters/yx_scope_adapter.dart
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
// ignore_for_file: invalid_use_of_protected_member
|
||||||
|
|
||||||
|
import 'package:benchmark_di/di_adapters/di_adapter.dart';
|
||||||
|
import 'package:benchmark_di/scenarios/universal_binding_mode.dart';
|
||||||
|
import 'package:benchmark_di/scenarios/universal_scenario.dart';
|
||||||
|
import 'package:benchmark_di/scenarios/universal_service.dart';
|
||||||
|
import 'package:benchmark_di/di_adapters/yx_scope_universal_container.dart';
|
||||||
|
|
||||||
|
/// DIAdapter для yx_scope UniversalYxScopeContainer
|
||||||
|
class YxScopeAdapter extends DIAdapter<UniversalYxScopeContainer> {
|
||||||
|
late UniversalYxScopeContainer _scope;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void setupDependencies(void Function(UniversalYxScopeContainer container) registration) {
|
||||||
|
_scope = UniversalYxScopeContainer();
|
||||||
|
registration(_scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
T resolve<T extends Object>({String? named}) {
|
||||||
|
return _scope.depFor<T>(name: named).get;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<T> resolveAsync<T extends Object>({String? named}) async {
|
||||||
|
return resolve<T>(named: named);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void teardown() {
|
||||||
|
// У yx_scope нет явного dispose на ScopeContainer, но можно добавить очистку Map/Deps если потребуется
|
||||||
|
// Ничего не делаем
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
YxScopeAdapter openSubScope(String name) {
|
||||||
|
// Для простоты всегда возвращаем новый контейнер, сабскоупы не реализованы явно
|
||||||
|
return YxScopeAdapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> waitForAsyncReady() async {
|
||||||
|
// Все зависимости синхронны
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Registration<UniversalYxScopeContainer> universalRegistration<S extends Enum>({
|
||||||
|
required S scenario,
|
||||||
|
required int chainCount,
|
||||||
|
required int nestingDepth,
|
||||||
|
required UniversalBindingMode bindingMode,
|
||||||
|
}) {
|
||||||
|
if (scenario is UniversalScenario) {
|
||||||
|
return (scope) {
|
||||||
|
switch (scenario) {
|
||||||
|
case UniversalScenario.asyncChain:
|
||||||
|
for (int chain = 1; chain <= chainCount; chain++) {
|
||||||
|
for (int level = 1; level <= nestingDepth; level++) {
|
||||||
|
final prevDepName = '${chain}_${level - 1}';
|
||||||
|
final depName = '${chain}_$level';
|
||||||
|
final dep = scope.dep<UniversalService>(
|
||||||
|
() => UniversalServiceImpl(
|
||||||
|
value: depName,
|
||||||
|
dependency: level > 1
|
||||||
|
? scope.depFor<UniversalService>(name: prevDepName).get
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
name: depName,
|
||||||
|
);
|
||||||
|
scope.register<UniversalService>(dep, name: depName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case UniversalScenario.register:
|
||||||
|
final dep = scope.dep<UniversalService>(
|
||||||
|
() => UniversalServiceImpl(value: 'reg', dependency: null),
|
||||||
|
);
|
||||||
|
scope.register<UniversalService>(dep);
|
||||||
|
break;
|
||||||
|
case UniversalScenario.named:
|
||||||
|
final dep1 = scope.dep<UniversalService>(
|
||||||
|
() => UniversalServiceImpl(value: 'impl1'),
|
||||||
|
name: 'impl1',
|
||||||
|
);
|
||||||
|
final dep2 = scope.dep<UniversalService>(
|
||||||
|
() => UniversalServiceImpl(value: 'impl2'),
|
||||||
|
name: 'impl2',
|
||||||
|
);
|
||||||
|
scope.register<UniversalService>(dep1, name: 'impl1');
|
||||||
|
scope.register<UniversalService>(dep2, name: 'impl2');
|
||||||
|
break;
|
||||||
|
case UniversalScenario.chain:
|
||||||
|
for (int chain = 1; chain <= chainCount; chain++) {
|
||||||
|
for (int level = 1; level <= nestingDepth; level++) {
|
||||||
|
final prevDepName = '${chain}_${level - 1}';
|
||||||
|
final depName = '${chain}_$level';
|
||||||
|
final dep = scope.dep<UniversalService>(
|
||||||
|
() => UniversalServiceImpl(
|
||||||
|
value: depName,
|
||||||
|
dependency: level > 1
|
||||||
|
? scope.depFor<UniversalService>(name: prevDepName).get
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
name: depName,
|
||||||
|
);
|
||||||
|
scope.register<UniversalService>(dep, name: depName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case UniversalScenario.override:
|
||||||
|
// handled at benchmark level
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (scenario == UniversalScenario.chain || scenario == UniversalScenario.override) {
|
||||||
|
final depName = '${chainCount}_$nestingDepth';
|
||||||
|
final lastDep = scope.dep<UniversalService>(
|
||||||
|
() => scope.depFor<UniversalService>(name: depName).get,
|
||||||
|
);
|
||||||
|
scope.register<UniversalService>(lastDep);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw UnsupportedError('Scenario $scenario not supported by YxScopeAdapter');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import 'package:yx_scope/yx_scope.dart';
|
||||||
|
|
||||||
|
/// Universal container for dynamic DI registration in yx_scope (for benchmarks).
|
||||||
|
/// Allows to register and resolve deps by name/type at runtime.
|
||||||
|
class UniversalYxScopeContainer extends ScopeContainer {
|
||||||
|
final Map<String, Dep<dynamic>> _namedDeps = {};
|
||||||
|
final Map<Type, Dep<dynamic>> _typedDeps = {};
|
||||||
|
|
||||||
|
void register<T>(Dep<T> dep, {String? name}) {
|
||||||
|
if (name != null) {
|
||||||
|
_namedDeps[_depKey<T>(name)] = dep;
|
||||||
|
} else {
|
||||||
|
_typedDeps[T] = dep;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dep<T> depFor<T>({String? name}) {
|
||||||
|
if (name != null) {
|
||||||
|
final dep = _namedDeps[_depKey<T>(name)];
|
||||||
|
if (dep is Dep<T>) return dep;
|
||||||
|
throw Exception('No dep for type $T/$name');
|
||||||
|
} else {
|
||||||
|
final dep = _typedDeps[T];
|
||||||
|
if (dep is Dep<T>) return dep;
|
||||||
|
throw Exception('No dep for type $T');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static String _depKey<T>(String name) => '$T@$name';
|
||||||
|
}
|
||||||
@@ -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});
|
||||||
@@ -14,4 +14,4 @@ abstract class UniversalService {
|
|||||||
/// Default implementation for [UniversalService] used in service chains.
|
/// Default implementation for [UniversalService] used in service chains.
|
||||||
class UniversalServiceImpl extends UniversalService {
|
class UniversalServiceImpl extends UniversalService {
|
||||||
UniversalServiceImpl({required super.value, super.dependency});
|
UniversalServiceImpl({required super.value, super.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.10"
|
||||||
collection:
|
collection:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -72,6 +72,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "8.2.0"
|
version: "8.2.0"
|
||||||
|
kiwi:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: kiwi
|
||||||
|
sha256: d078364a90fb1b93852bb74468efdf4aaae35c036c538c1cf4f9c74a19df9a61
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "5.0.1"
|
||||||
lazy_memo:
|
lazy_memo:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -128,5 +136,13 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
|
yx_scope:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: yx_scope
|
||||||
|
sha256: "9ba98b442261596311363bf7361622e5ccc67189705b8d042ca23c9de366f8bf"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.2"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.6.0 <4.0.0"
|
dart: ">=3.6.0 <4.0.0"
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ dependencies:
|
|||||||
args: ^2.7.0
|
args: ^2.7.0
|
||||||
get_it: ^8.2.0
|
get_it: ^8.2.0
|
||||||
riverpod: ^2.6.1
|
riverpod: ^2.6.1
|
||||||
|
kiwi: ^5.0.1
|
||||||
|
yx_scope: ^1.1.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
lints: ^5.0.0
|
lints: ^5.0.0
|
||||||
|
|||||||
@@ -1,3 +1,33 @@
|
|||||||
|
## 3.0.0-dev.12
|
||||||
|
|
||||||
|
- **FIX**(scope): prevent concurrent modification in dispose().
|
||||||
|
- **FIX**(binding): fix unterminated string literal and syntax issues in binding.dart.
|
||||||
|
|
||||||
|
## 3.0.0-dev.11
|
||||||
|
|
||||||
|
- **FIX**(scope): prevent concurrent modification in dispose().
|
||||||
|
- **FIX**(binding): fix unterminated string literal and syntax issues in binding.dart.
|
||||||
|
|
||||||
|
## 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 `_ | |||||||