Andrea Koutifaris
1 min readMay 7, 2021

--

In general, not just for react, the concept of using (computed) getters to provide derived properties from a model is a good practice, but too often disregarded.

Writing lines to keep some values updated when a model change is really bad. The worst thing is that people thinks that by avoiding getters they make a more "performant" piece of code, because you don't make calculations to get the derived state. This is non sense. And it is really hard to make people understand what performance optimization is about. The so called "micro" optimization is most of the time garbage.

As you write in the article, when (and only when) there are performance issues (after having MEASURED those issues) in computing a derived state, then there are various techniques to deal with such problem.

Finally, a (computed) getter consumes CPU time, but an additional property consumes memory. Someone may thing that single property may consume very a few memory... I may argument that a fraction of a millisecond to get the value from a getter consumes very a few CPU time... So, why do we always consume memory to avoid CPU computation, when no optimization was needed in the first place? Did someone wrote something like caches being the root of all evil? Or was it about premature optimization?

Thanks for the article!

--

--

Andrea Koutifaris
Andrea Koutifaris

No responses yet