Performance: Pipe binding (parameter, method, controller, global)
MEDIUM IMPACT
This concept affects request processing speed and server response time by controlling when and how data validation and transformation occur in the request lifecycle.
import { Controller, Get, UsePipes, ValidationPipe } from '@nestjs/common'; @UsePipes(new ValidationPipe()) @Controller('items') export class ItemsController { @Get() findAll(@Query() query: QueryDto) { // handle request } }
import { Controller, Get, Query, ParseIntPipe } from '@nestjs/common'; @Controller('items') export class ItemsController { @Get() findAll(@Query('limit', new ParseIntPipe()) limit: number) { // handle request } }
| Pattern | Pipe Executions | CPU Usage | Request Latency | Verdict |
|---|---|---|---|---|
| Parameter-level binding | Multiple per request parameter | High | Increased | [X] Bad |
| Method-level binding | Once per method call | Medium | Moderate | [!] OK |
| Controller-level binding | Once per controller method call | Low | Improved | [OK] Good |
| Global binding without filtering | Every request | High | Increased | [X] Bad |
| Global binding with options | Filtered requests only | Low to Medium | Improved | [OK] Good |