Performance¶
diwire is designed to be fast by default, but there are a few knobs if you’re optimizing a hot path.
Use compilation¶
See Compilation.
In short:
leave
auto_compile=True(default) unless you need manual controlor call
container.compile()after all registrations
Prefer stable lifetimes for heavy dependencies¶
Make heavy clients singletons (HTTP clients, connection pools).
Make per-request resources scoped (DB sessions, unit-of-work).
Keep transient graphs lightweight.
Avoid unnecessary work inside factories¶
If a factory does expensive setup, consider:
turning it into a singleton
moving expensive work to app startup
using an async factory and resolving via
aresolve()