Performance: CRUD operations
MEDIUM IMPACT
CRUD operations impact server response time and client rendering speed, affecting how quickly users see and interact with data changes.
from fastapi import FastAPI import asyncio app = FastAPI() items = {} @app.get('/items/{item_id}') async def read_item(item_id: int): await asyncio.sleep(2) # Non-blocking placeholder for async DB call return items.get(item_id, {'error': 'Not found'}) @app.post('/items/{item_id}') async def create_item(item_id: int, item: dict): items[item_id] = item return item
from fastapi import FastAPI app = FastAPI() items = {} @app.get('/items/{item_id}') async def read_item(item_id: int): # Simulate slow DB call import time time.sleep(2) return items.get(item_id, {'error': 'Not found'}) @app.post('/items/{item_id}') async def create_item(item_id: int, item: dict): items[item_id] = item return item
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous blocking DB calls | Minimal | Multiple due to delayed updates | High due to delayed content | [X] Bad |
| Asynchronous non-blocking DB calls | Minimal | Single or minimal | Low due to faster content delivery | [OK] Good |
| Sequential synchronous updates | Minimal | Multiple reflows due to slow updates | High | [X] Bad |
| Parallel asynchronous updates | Minimal | Single reflow after batch update | Low | [OK] Good |
| Returning full large data sets | Many DOM nodes | Multiple reflows | High paint cost | [X] Bad |
| Paginated data responses | Few DOM nodes per page | Single reflow per page | Low paint cost | [OK] Good |