Performance: Gateway decorator
MEDIUM IMPACT
This affects the initialization and event handling speed of WebSocket gateways in a NestJS application, impacting interaction responsiveness.
import { WebSocketGateway, SubscribeMessage } from '@nestjs/websockets'; @WebSocketGateway() export class ChatGateway { @SubscribeMessage('message') async handleMessage(client: any, payload: any) { // offload heavy work asynchronously await new Promise(resolve => setTimeout(resolve, 0)); return { event: 'message', data: payload }; } }
import { WebSocketGateway, SubscribeMessage } from '@nestjs/websockets'; @WebSocketGateway() export class ChatGateway { @SubscribeMessage('message') handleMessage(client: any, payload: any) { // heavy synchronous processing for(let i = 0; i < 1000000000; i++) {} return { event: 'message', data: payload }; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous event handler | N/A | N/A | N/A | [X] Bad |
| Asynchronous lightweight event handler | N/A | N/A | N/A | [OK] Good |