Speed Up Slow Python Calls
Finds why a quick Python call loads a big model or library, then fixes it with lazy loading and tests.
Claude's review
7/10 Concrete Python lazy loading method with fresh process timing, import vs load checks and tests that assert the loader is never called.
We asked Claude the question you would ask: would I be glad I installed this? Two separate reviews, the second blind to the first, must both rate a skill 7 or higher before we sell it.
In detail
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.
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: deferring-heavy-dependencies
description: 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.
---
# 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
```python
# 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
```
`character_count` profiles as free and still takes 80 ms. Defer the field:
```python
# Good — built on first real use, then cached on the instance.
class TextAnalyzer:
def __init__(self) -> None:
self._spell_checker: SpellChecker | None = None
@property
def spell_checker(self) -> SpellChecker:
if self._spell_checker is None:
self._spell_checker = SpellChecker()
return self._spell_checker
```
`functools.cached_property` covers the common case with less code, but it is not
...From wdm0006's repository, MIT licence.
Related skills
-
Checked
Rust code review
Reviews Rust code for idiom, errors, safety and API design, with a ranked report and a fix for every finding.
7/101 credit -
Checked
Java Debugging Guide
Finds the cause of Java bugs and failing tests, and attaches a debugger safely in Maven, Gradle, Spring or Docker.
7/101 credit -
Checked
Python games with pygame
Builds and debugs 2D pygame games with a proper loop and delta time, so they run the same on any PC.
7/101 credit -
Checked
Go Benchmarking and Profiling
Writes Go benchmarks, profiles them with pprof and proves each speedup with benchstat before you claim it.
7/101 credit -
Checked
nvMolKit GPU cheminformatics
Writes nvMolKit code for GPU fingerprints, similarity and clustering, so molecule searches run far faster.
7/101 credit -
Checked
Modern Java Coding
Writes and reviews modern Java 21 and 25 code with records, sealed types, pattern matching and virtual threads.
7/101 credit