Performance: Chat history management
MEDIUM IMPACT
This concept affects the responsiveness and memory usage of chat applications by managing how conversation data is stored and retrieved.
from collections import deque class ChatMemory: def __init__(self, max_messages=50): self.history = deque(maxlen=max_messages) def add_message(self, message): self.history.append(message) def get_history(self): return list(self.history)
class ChatMemory: def __init__(self): self.history = [] def add_message(self, message): self.history.append(message) def get_history(self): return self.history
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unlimited chat history in memory | High (many nodes if rendered) | Multiple reflows as history grows | High paint cost due to large DOM | [X] Bad |
| Limited chat history with deque | Low (fixed number of nodes) | Single reflow on update | Low paint cost with small DOM | [OK] Good |