Bird
0
0

Why does this impure pipe cause performance issues?

medium📝 Debug Q7 of 15
Angular - Pipes
Why does this impure pipe cause performance issues?
@Pipe({name: 'slowPipe', pure: false})
export class SlowPipe implements PipeTransform {
transform(value: any) {
for(let i=0; i<1000000; i++) {}
return value;
}
}
AIt does not implement PipeTransform correctly
BIt caches the result and never updates
CIt runs the expensive loop on every change detection cycle
DIt only runs once when the component loads
Step-by-Step Solution
Solution:
  1. Step 1: Analyze impure pipe behavior

    Impure pipes run on every change detection cycle.
  2. Step 2: Identify expensive operation

    The loop runs a million times each cycle, causing slow performance.
  3. Final Answer:

    It runs the expensive loop on every change detection cycle -> Option C
  4. Quick Check:

    Impure pipe + expensive code = slow app [OK]
Quick Trick: Avoid heavy work in impure pipes to prevent slowdowns [OK]
Common Mistakes:
  • Assuming impure pipes run once
  • Thinking result is cached
  • Believing PipeTransform is not implemented

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes