Invocation of getters with ComputedFrom decorator

We’re currently using aurelia in a medium large application and we’re seing our computed properties being executed each time they are being accessed and not only every time their dependencies change.

Is this correct behaviour? I would expect that since we are declaring the dependencies of the getter, we could memoize the function based on the values of the dependencies.

I’m also noticing that the getter functions are invoked the number of times they are called + 1.

Here’s a reproduction: https://gist.dumber.app/?gist=651425de5771ff2380d0516ddee15036

1 Like

This is probably the same discussion over on github: https://github.com/aurelia/binding/pull/398
Probably same question here: https://github.com/aurelia/binding/issues/732

Seems like it’s not part of the core framework but there exists a plugin for the behaviour: https://github.com/bigopon/aurelia-deep-computed

After some searching I guess the behaviour I was expecting was something more similar to how Ember does it here https://api.emberjs.com/ember/3.21/classes/ComputedProperty/

1 Like

In v1, we don’t replace the getter decorated witt @computedFrom, that’s why you are seeing this behavior, because it’s not possible to cache without wrapping the getter.
In the plugin you mentioned, the getter is wrapped and it’s able to cache it. In v2, this should also be the default behavior. I’m refactoring a few bits around observation system to enable this.

1 Like