Pure Pipes

Published on August 08, 2019

← Back to tips

Explicitly tell Angular whether your pipes are pure or not using the pure: true in @Pipe decoration options.

This helps angular to decide on how many instances of Pipe needs to be created for the entire application.

πŸ”½ Reasoning

Only one instance of Pipe is created if the pipe is pure (as it is always expected to provide same output for any specific input)

If your pipe is impure, they can’t be shared across templates and so multiple instances are created (which in turn uses more memory in heap)

This might feel like a very trivial optimization. But for an enterprise level angular app which would have 20 - 30+ pipes for various use-cases, the memory footprint is considerably big.

πŸŽ‰ Interested in Frontend or Indie-hacking?

I talk about the latest in frontend, along with my experience in building various (Indie) side-projects