Performance: Environment variable management
MEDIUM IMPACT
This affects the startup time and configuration loading speed of the FastAPI application.
import os from dotenv import load_dotenv load_dotenv() # called once at startup secret = os.getenv('SECRET_KEY') def read_root(): return {"secret": secret}
import os from dotenv import load_dotenv def read_root(): load_dotenv() # called inside a route handler secret = os.getenv('SECRET_KEY') return {"secret": secret}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Load env vars inside route | N/A | N/A | Blocks response start, delays paint | [X] Bad |
| Load env vars once at startup | N/A | N/A | Fast response start, no blocking | [OK] Good |
| Repeated os.getenv calls in handler | N/A | N/A | Minor CPU overhead, slight delay | [!] OK |
| Cache env vars in constants | N/A | N/A | Minimal overhead, fast response | [OK] Good |