Performance: Why real-time matters
HIGH IMPACT
Real-time affects how quickly users see updates and interact with the app, impacting responsiveness and user experience.
const http = require('http'); const express = require('express'); const { Server } = require('socket.io'); const app = express(); const server = http.createServer(app); const io = new Server(server); io.on('connection', (socket) => { // Push updates instantly socket.emit('update', { data: 'new data' }); }); server.listen(3000);
app.get('/updates', (req, res) => { // Endpoint for client-side polling every 5 seconds res.json({ data: 'new data' }); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Polling HTTP requests every 5 seconds | Multiple repeated DOM updates | Multiple reflows per update | High paint cost due to frequent updates | [X] Bad |
| WebSocket push updates | Single DOM update per event | Minimal reflows triggered | Lower paint cost with targeted updates | [OK] Good |