Performance: Calling tasks asynchronously
HIGH IMPACT
This concept affects how quickly the main web request responds by offloading long tasks to run separately, improving user experience and server responsiveness.
from flask import Flask, request from threading import Thread app = Flask(__name__) def async_task(): long_task() @app.route('/process') def process(): Thread(target=async_task).start() return "Task started asynchronously"
from flask import Flask, request app = Flask(__name__) @app.route('/process') def process(): # Long task runs synchronously result = long_task() return f"Task done: {result}"
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous long task | Minimal | 0 | Blocks response delaying paint | [X] Bad |
| Asynchronous task with thread | Minimal | 0 | Immediate response enables fast paint | [OK] Good |