0
0
NestJSframework~8 mins

Why interceptors add cross-cutting logic in NestJS - Performance Evidence

Choose your learning style9 modes available
Performance: Why interceptors add cross-cutting logic
MEDIUM IMPACT
Interceptors affect the request-response cycle timing and can impact interaction responsiveness by adding extra processing steps.
Adding logging or timing logic to many requests
NestJS
Use lightweight, asynchronous interceptors that delegate heavy work outside the request cycle or use caching.
Non-blocking logic keeps the event loop free, improving responsiveness.
📈 Performance GainReduces blocking time to under 5ms per request
Adding logging or timing logic to many requests
NestJS
Use interceptors that perform heavy synchronous operations or blocking calls inside intercept method.
This blocks the event loop and delays response, increasing interaction latency.
📉 Performance CostBlocks rendering for 50-100ms per request depending on logic complexity
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Heavy synchronous interceptor logicN/A (server-side)N/AN/A[X] Bad
Lightweight asynchronous interceptor logicN/AN/AN/A[OK] Good
Rendering Pipeline
Interceptors run during the server-side request handling before sending the response, adding steps in the processing pipeline that can delay the final response sent to the client.
Request Handling
Response Preparation
⚠️ BottleneckSynchronous or heavy processing inside interceptors
Core Web Vital Affected
INP
Interceptors affect the request-response cycle timing and can impact interaction responsiveness by adding extra processing steps.
Optimization Tips
1Avoid heavy synchronous work inside interceptors to prevent blocking the event loop.
2Use asynchronous operations and caching in interceptors to keep response times low.
3Profile server response times to detect interceptor-induced delays.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance risk of using interceptors with heavy synchronous logic?
AThey increase DOM reflows on the client
BThey block the event loop and delay responses
CThey add extra CSS paint cost
DThey reduce bundle size
DevTools: Network and Performance panels
How to check: Record a request in Network panel and check response time; use Performance panel to profile server response delays.
What to look for: Look for long server response times and blocking periods indicating interceptor overhead