Performance: Room-based messaging
This affects real-time message delivery speed and server load during user interactions in chat rooms.
socket.emit('message', data, room=room_id)
for user in all_users: socket.emit('message', data, room=user.id)
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Individual emits per user | Low | Low | Low | [X] Bad |
| Single emit to room | Low | Low | Low | [OK] Good |
from flask_socketio import send, join_room
@socketio.on('join')
def on_join(data):
room = data['room']
join_room(room)
send('User has entered the room.', room=room)@socketio.on('leave')
def on_leave(data):
room = data['room']
leave_room()
send('User has left the room.', room=room)Pass the test and this pattern moves unknown