Performance: WebSocket events handling
MEDIUM IMPACT
This affects the responsiveness and smoothness of real-time updates on the page by controlling how WebSocket events are processed and rendered.
from flask_socketio import SocketIO, emit import threading socketio = SocketIO(app) def background_task(data): result = complex_calculation(data) socketio.emit('response', result) @socketio.on('message') def handle_message(data): threading.Thread(target=background_task, args=(data,)).start()
from flask_socketio import SocketIO, emit socketio = SocketIO(app) @socketio.on('message') def handle_message(data): # Heavy processing on main thread result = complex_calculation(data) emit('response', result)
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking heavy processing in event handler | Multiple DOM updates per event | Multiple reflows if DOM updated repeatedly | High paint cost due to frequent layout changes | [X] Bad |
| Background thread processing with batched DOM updates | Batched DOM updates | Single reflow per batch | Lower paint cost due to fewer layout changes | [OK] Good |