Performance: Background file processing
HIGH IMPACT
This concept affects page load speed and interaction responsiveness by offloading heavy file processing tasks from the main request thread.
from fastapi import FastAPI, UploadFile, BackgroundTasks app = FastAPI() def heavy_processing(content: bytes): # Process file in background pass @app.post('/upload') async def upload(file: UploadFile, background_tasks: BackgroundTasks): content = await file.read() background_tasks.add_task(heavy_processing, content) return {'status': 'processing started'}
from fastapi import FastAPI, UploadFile app = FastAPI() @app.post('/upload') async def upload(file: UploadFile): content = await file.read() # Process file synchronously here result = heavy_processing(content) return {'status': 'done', 'result': result}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous file processing in request | N/A | N/A | Blocks response, delays paint | [X] Bad |
| Background file processing with BackgroundTasks | N/A | N/A | Immediate response, no blocking | [OK] Good |