← All demos

Scan Performance: Eager vs Lazy

See the difference between eager scanning (imports everything upfront) and lazy scanning (defers imports until you actually resolve a dependency). Three adapters with expensive imports tell the whole story.

Load what you need, when you need it.

The Problem

Eager scanning imports every module in your package at startup. If adapters load heavy SDKs (Stripe, SendGrid, analytics), your app pays the cost for all of them, even if it only needs one.

The Solution

Pass lazy=True to container.scan(). Dioxide uses AST parsing to discover adapter-to-port mappings without importing. Modules load only when resolve() is called.

Source Code

Browse on GitHub