Performance: Multiple file uploads
MEDIUM IMPACT
This affects the page load speed and interaction responsiveness when users upload multiple files simultaneously.
from fastapi import FastAPI, File, UploadFile from typing import List import asyncio app = FastAPI() async def process_file(file: UploadFile): content = await file.read() # simulate async processing await asyncio.sleep(0) return {'filename': file.filename, 'size': len(content)} @app.post('/upload') async def upload_files(files: List[UploadFile] = File(...)): tasks = [process_file(file) for file in files] results = await asyncio.gather(*tasks) return results
from fastapi import FastAPI, File, UploadFile from typing import List app = FastAPI() @app.post('/upload') async def upload_files(files: List[UploadFile] = File(...)): results = [] for file in files: content = await file.read() # process file content synchronously results.append({'filename': file.filename, 'size': len(content)}) return results
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Sequential file read | N/A (server-side) | N/A | N/A | [X] Bad |
| Concurrent async file read | N/A (server-side) | N/A | N/A | [OK] Good |