The difference between calling a function inside a template and using a component's property #133
Replies: 5 comments 2 replies
-
If I only knew what this bytecode means |
Beta Was this translation helpful? Give feedback.
-
Agree, the generated code doesn't seem to have much of a difference. It's the runtime performance that can be a major difference. My understanding is, |
Beta Was this translation helpful? Give feedback.
-
So, main point here that angular during change detection in any case will compare prev and current values. (It's not a question how much times cd happens) And not much difference in below example:
But in more real life example it has more perfomance impact:
And can be "fixed" like
|
Beta Was this translation helpful? Give feedback.
-
I have this StackBlitz where you can test performance of change detection cycle with 1000 components. Imperative do not call any functions or getters, declarative do and compliant use memoization for array and objects operations: It is taken from my article on declarative approach in Angular: |
Beta Was this translation helpful? Give feedback.
-
for quite a long time I use a pipe (my thought, it should be in a core) to call template functions effectively
that simple, and it runs only for arg change, even though written in template |
Beta Was this translation helpful? Give feedback.
-
Many believe that calling functions inside Angular's template is bad by itself. It's not. Here's the comparison between using a property and a function call. The difference is negligible - just a couple of bytecode instruction.
What's important is how many times your access that property or call the function.
Beta Was this translation helpful? Give feedback.
All reactions