0
0
NestJSframework~8 mins

Whitelist and transform options in NestJS - Performance & Optimization

Choose your learning style9 modes available
Performance: Whitelist and transform options
MEDIUM IMPACT
This affects the request processing speed and memory usage by controlling which properties are accepted and how input data is transformed before reaching business logic.
Validating and transforming incoming request data in NestJS
NestJS
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
Automatically removes unwanted properties and converts input types to expected DTO classes, reducing manual work and speeding up processing.
📈 Performance GainSaves CPU cycles by skipping manual filtering and parsing, improves INP by faster validation and transformation.
Validating and transforming incoming request data in NestJS
NestJS
app.useGlobalPipes(new ValidationPipe({ whitelist: false, transform: false }));
Accepts all properties including unwanted ones and does not convert input types, causing extra validation and manual parsing later.
📉 Performance CostTriggers extra CPU cycles for manual checks and can increase memory usage by keeping unwanted data.
Performance Comparison
PatternCPU UsageMemory UsageValidation SpeedVerdict
Whitelist: false, Transform: falseHigh (manual checks)Higher (extra data kept)Slower (manual parsing)[X] Bad
Whitelist: true, Transform: trueLower (automatic filtering)Lower (only needed data)Faster (auto conversion)[OK] Good
Rendering Pipeline
Whitelist and transform options run during the request lifecycle before controller logic, affecting how data is parsed and validated.
Request Parsing
Validation
Transformation
⚠️ BottleneckValidation stage can be costly if whitelist is off and transform is disabled, causing extra manual processing.
Core Web Vital Affected
INP
This affects the request processing speed and memory usage by controlling which properties are accepted and how input data is transformed before reaching business logic.
Optimization Tips
1Always enable whitelist to drop unwanted properties early.
2Enable transform to convert input types automatically.
3Disabling whitelist or transform increases CPU and memory usage.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of enabling whitelist in NestJS ValidationPipe?
AIt delays validation until after controller logic.
BIt caches all incoming requests for faster access.
CIt removes unwanted properties early, reducing processing time.
DIt disables all validation to speed up requests.
DevTools: Performance
How to check: Record a profile while sending requests with and without whitelist/transform enabled. Compare CPU time spent in validation and parsing.
What to look for: Look for reduced CPU time and faster function execution in validation pipes when whitelist and transform are enabled.