Performance: Why authentication matters
MEDIUM IMPACT
Authentication affects page load speed and interaction responsiveness by adding server-side checks and client-server communication overhead.
from flask import Flask, request, redirect import asyncio app = Flask(__name__) async def get_user_data_async(user): # simulate async database query await asyncio.sleep(0.3) return {'info': 'user data'} @app.route('/dashboard') async def dashboard(): user = request.cookies.get('user') if not user: return redirect('/login') data = await get_user_data_async(user) # async non-blocking call return f"Welcome {user}, your data: {data}"
from flask import Flask, request, redirect app = Flask(__name__) def get_user_data(user): # simulate heavy database query import time time.sleep(0.3) return {'info': 'user data'} @app.route('/dashboard') def dashboard(): user = request.cookies.get('user') if not user: return redirect('/login') # heavy database query here data = get_user_data(user) # synchronous blocking call return f"Welcome {user}, your data: {data}"
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous auth with blocking DB calls | Minimal | 0 | Delayed due to slow response | [X] Bad |
| Asynchronous auth with cached sessions | Minimal | 0 | Fast initial paint | [OK] Good |