Performance: Response transformation
MEDIUM IMPACT
This affects how fast the server sends the final data to the client and how much processing happens before the response is sent.
import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common'; import { map } from 'rxjs/operators'; @Injectable() export class LightTransformInterceptor implements NestInterceptor { intercept(context: ExecutionContext, next: CallHandler) { return next.handle().pipe( map(data => ({ ...data, value: data.value + 1 })), ); } }
import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common'; import { map } from 'rxjs/operators'; @Injectable() export class HeavyTransformInterceptor implements NestInterceptor { intercept(context: ExecutionContext, next: CallHandler) { return next.handle().pipe( map(data => { // Heavy synchronous transformation for (let i = 0; i < 1000000; i++) { data.value += i; } return data; }), ); } }
| Pattern | Server Processing | Response Delay | Impact on LCP | Verdict |
|---|---|---|---|---|
| Heavy synchronous transformation | High CPU usage | 100+ ms delay | Significant LCP increase | [X] Bad |
| Lightweight transformation | Minimal CPU usage | Under 10 ms delay | Minimal LCP impact | [OK] Good |