Performance: class-validator decorators
MEDIUM IMPACT
This affects the server-side validation step before data processing, impacting request handling speed and response time.
import { IsString, IsInt, Min, Max, Length } from 'class-validator'; export class UserDto { @IsString() @Length(5, 50) username: string; @IsInt() @Min(0) @Max(150) age: number; @IsString() @Length(0, 255) bio: string; // Removed description field to reduce validation overhead }
import { IsString, IsInt, Min, Max, Length } from 'class-validator'; export class UserDto { @IsString() @Length(5, 50) username: string; @IsInt() @Min(0) @Max(150) age: number; @IsString() @Length(0, 255) bio: string; @IsString() @Length(0, 1000) description: string; }
| Pattern | Validation CPU Cost | Request Latency Impact | Memory Usage | Verdict |
|---|---|---|---|---|
| Many complex decorators on large DTO | High CPU usage | Adds 10-30ms latency | Moderate | [X] Bad |
| Minimal decorators on essential fields | Low CPU usage | Adds 2-5ms latency | Low | [OK] Good |