TGViewer
samdark blog ☕️ (Alexander Makarov) samdark blog ☕️ (Alexander Makarov) @samdark_blog · 1.62K subscribers
Post #103 1.12K
✈️ Always defer initialization

Modern frameworks utilize dependency inversion, with auto-wiring and DI containers used to populate the dependency tree. However, this can lead to large dependency trees, which is not inherently problematic, as instantiation is typically inexpensive. Nevertheless, if a service has heavy initialization in its constructor, it can significantly impact performance.

For example, the Symfony console initially defined command names and descriptions in non-static methods. As a result, when called without a command name, the console would instantiate every available command, some of which had expensive initializations such as connecting to a database, verifying API credentials, or reading files from disk. Although this issue has been resolved by using static metadata, it highlights the importance of deferring initialization for optimal performance.

To avoid performance issues caused by heavy initialization, it is crucial to defer initialization for as long as possible. By doing so, you can ensure that your application runs smoothly, regardless of the complexity of the dependency tree.
  • 👍 15
  • 🔥 2
More from @samdark_blog
  1. Sep 23, 2026On quantum computing and IonQ Error Decoder In my university we were told many times that…
  2. Sep 22, 2026⏩ Re-benchmarked different ways to serve PHP Some time ago I've made some benchmarks to fi…
  3. Sep 9, 2026Пыхник’26 — целая неделя PHP! С 28 сентября по 2 октября пройдёт Пыхник’26 — онлайн-конфер…
  4. Sep 8, 2026My name is Taras Soroka. I’m a CTO, digital transformation consultant, mentor, and the hos…
  5. Sep 8, 2026💬 Bjarne Stroustrup on AI Code will still be written by humans, and they will rely on abs…
  6. Sep 7, 2026🌬 TION MagicAir CO² sensor calibration via USB HID I have a Tion breather and a MagicAir…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →