circuitry 0.5.1
circuitry: ^0.5.1 copied to clipboard
A pure Dart 3 zero-codegen, Directed Acyclic Graph (DAG) based dependency injection engine.
Changelog #
0.5.1 #
Documentation #
- Added
circuitry_analyzer_pluginsetup instructions toREADME.mdfor edit-time static DAG validation and best-practice lints.
0.5.0 #
Performance #
- Type-Indexed Fast-Path for Untagged Singletons:
- Maintained dedicated
_untaggedInstancesmapped directly by canonical DartTypeto eliminate runtime record tuple(T, null)allocations on everycircuit.get<T>(). - Achieved ~78% lower lookup latency (from 126.6 ns down to 24.9–28.3 ns) and 4.5x higher throughput (>35M–40M ops/sec) with zero nursery heap allocations.
- Maintained dedicated
- Single-Hash Assignment Lookups:
- Replaced double-hash traversals (
containsKey+[]) with single-lookup assignment (final cached = _instances[key]; if (cached != null) return cached;) in runtime resolution and topological depth computation.
- Replaced double-hash traversals (
- Reproducible Benchmark Suite:
- Added standalone benchmark suite in
benchmark/covering monomorphic, polymorphic/interleaved retrieval, and DAG compilation with dead-code elimination protection and loop overhead calibration.
- Added standalone benchmark suite in
0.2.0 #
Features #
- Ambient
CircuitRegistry& DevTools Integration:- Automatically tracks
Circuitinstances in debug mode (assert(...)), tracking status, wire resolution counts, and lifecycle events. - Exposes
registerVmServiceExtensions()andunregisterVmServiceExtensions()for explicit Dart VM Service extension lifecycle control:ext.circuitry.getCircuits: Lists all active circuits, descriptors, and metadata.ext.circuitry.getCircuitGraph: Returns full graph schema, waves, wire details, dependencies, and resolution timings.ext.circuitry.forceResolveWire: Triggers on-demand wire resolution across the VM Service protocol.
- Streams real-time lifecycle events via
developer.postEvent('circuitry:lifecycle', ...). - Added optional
debugTagidentifier toCircuit.build(wires, debugTag: '...')for multi-circuit identification in DevTools. - Decoupled the 15 MB compiled DevTools extension web bundle into the opt-in
circuitry_devtools_extensionpackage, reducingcircuitrypackage archive size to ~28 KB. - Zero-overhead in profile and release builds: assertions are disabled,
CircuitRegistrymethods and properties become no-ops, and telemetry call sites are fully tree-shaken by the compiler.
- Automatically tracks
- Core Introspection API & Exporters:
- Precomputes reverse dependency adjacency in
CircuitGraph.compile()for instant O(1) direct and transitive queries. - Added
circuit.inspect()returning an immutableCircuitIntrospectionsnapshot withdependentsOf,dependenciesOf,transitiveDependentsOf,transitiveDependenciesOf, and topological order queries. - Built-in visual diagram generation via
toMermaid()producing valid Mermaid flowchart syntax with wave subgraphs and edge arrows. - Built-in structured JSON serialization via
toJson()for exporting graph schemas. - Zero release overhead: 100% tree-shaken when unused in production code.
- Precomputes reverse dependency adjacency in
- Fail-Fast Async Wave Resolution with Immediate Rollback:
- Parallel topological wave execution now uses
Future.waitwitheagerError: trueto fail immediately upon the first encountered error instead of waiting for long-running concurrent sibling wires. - Enhanced lifecycle rollback safety: automatically tears down already resolved instances in reverse topological order, and disposes late-completing in-flight wires (
if (_isDisposed) await wire.disposeInstance(...)) to prevent resource leaks and unhandled exceptions.
- Parallel topological wave execution now uses
- Modular DAG Compiler & Container Decomposition:
- Separated static graph validation and compilation (
CircuitGraphinsrc/graph.dart) from runtime instance caching and lifecycle execution (Circuitinsrc/circuit.dart). - Extracted helper modules
src/utils.dartandsrc/extensions.dart. - Migrated engine codebase to modern Dart 3.14+ primary and concise constructors, switch expressions, and contextual dot-shorthands.
- Separated static graph validation and compilation (
0.1.0 #
Initial release of Circuitry: a pure Dart 3.14+ zero-codegen, Directed Acyclic Graph (DAG) based dependency injection engine.
Features #
- Zero-Codegen & Reflection-Free: Pure modern Dart without code generation, mirrors, or reflection.
- Record Tuple Keys (
WireKey): Strongly typed wire keys(Type, Enum?)supporting dot-shorthands (e.g.tag: .prod) and distinct registrations of the same generic Dart type. - Declarative Wires:
Wire<T>: Synchronous, lazy singletons constructed on first access or when required by dependent wires.AsyncWire<T>: Asynchronous singletons resolved duringCircuit.build(wires)with lifecycle hooks (onDispose).
- DAG Static Validation: Pre-execution verification preventing invalid dependency graphs:
- Detects duplicate wire keys (
DuplicateWireException). - Identifies missing dependencies (
MissingWireException). - Detects dependency cycles with exact cycle paths (
CircularDependencyException).
- Detects duplicate wire keys (
- Parallel Topological Wave Resolution: Asynchronous singletons are resolved concurrently level-by-level using
Future.wait, rolling back and disposing previously created instances if an error occurs during build. - Type-Safe Accumulator Chaining: Fluent dependency declarations with
Wire.takes<A>(),Wire.takesTagged<B, K>(tag),AsyncWire.takes<A>(), andAsyncWire.takesTagged<B, K>(tag). Supports constructor tear-offs (.to(Service.new)) and destructuring nested tuples for multiple dependencies. - Reverse Topological Wave Disposal: Idempotent teardown in reverse dependency waves (
leaves -> roots), awaiting parallel asynchronousonDisposehooks and aggregating failures intoDisposalException.