deferring-heavy-dependencies

Installation
SKILL.md

Deferring Heavy Dependencies

A word count should not load a language model. When it does, the cause is almost never the algorithm — it is that the cheap function shares a constructor, a factory, or an import with an expensive one. Profiling the function body finds nothing, because the time is spent before the body runs.

The cost is in construction, not in the call

# Bad — every instance builds a dictionary, whatever the caller asked for.
class TextAnalyzer:
    def __init__(self) -> None:
        self.spell_checker = SpellChecker()      # ~12 MB retained, ~80 ms

    def character_count(self, text: str) -> int:
        return len(text)                         # never touches spell_checker
Installs
4
GitHub Stars
87
First Seen
12 days ago
deferring-heavy-dependencies — wdm0006/python-skills