Performance: Extension initialization pattern
MEDIUM IMPACT
This pattern affects the app startup time and memory usage by controlling when and how extensions are initialized.
from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() def create_app(): app = Flask(__name__) db.init_app(app) return app
from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy(app) # In each blueprint file from app import db # Using db directly without app factory pattern
| Pattern | Extension Setup Calls | Memory Usage | Startup Time | Verdict |
|---|---|---|---|---|
| Direct init with app instance | Multiple if app recreated | Higher due to repeated setups | Slower due to repeated init | [X] Bad |
| Lazy init with init_app in factory | Single call per extension | Lower, reused instances | Faster startup | [OK] Good |