Deferring Heavy Dependencies

Keep expensive resources — ML models, spellcheck dictionaries, embedded databases, large third-party imports — off code paths that never use them. Covers constructor work paid by every caller, one-size factories that load the heaviest member for the cheapest request, load-and-unload-per-call masquerading as a cache, measuring per-call cost in a fresh process, telling a one-time import from a repeated model load, and the test fallout (patches that only now take effect, autouse fixtures that hide the dependency). Use when a trivially cheap operation takes hundreds of milliseconds, when adding a heavy dependency to a shared constructor or factory, or when reviewing a class whose `__init__` builds something most callers never touch.

wdm0006 Updated

File contents

wdm0006/python-skills/tree/main/skills/python/lazy-dependencies commit 56d6d3c61a

Frequently asked questions

npx skillmds@latest add wdm0006/deferring-heavy-dependencies