Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getter recalculation/caching? #25

Closed
rattrayalex opened this issue Apr 20, 2015 · 4 comments
Closed

Getter recalculation/caching? #25

rattrayalex opened this issue Apr 20, 2015 · 4 comments

Comments

@rattrayalex
Copy link

The docs don't mention whether Getters are recalculated every time, or just once between Store updates. It seems this implementation should allow at least per-update caching/memoization. Is that implemented/on the roadmap? Could this be mentioned in the docs?

@jordangarcia
Copy link
Contributor

In 0.5.x getter evaluation is pretty naive with no caching. In 0.6.0 which should be released soon (Optimizely is currently using the next branch and I would suggest you do as well) there is very efficient caching / memoization.

Here is an overview

Getters are only calculated whenever their dependencies change. So if the dependency is a keypath then it will only recalculate when that path in the app state map has changed (which can be done as a simple state.getIn(keyPath) !== oldState.getIn(keyPath) which is an O(log32(n)) operation. The other case is when a getter is dependent on other getters. Since every getter is a pure function then Nuclear will only recompute the getter if the values of its dependencies change.

You can read more of the implementation here:

https://github.com/optimizely/nuclear-js/blob/next-update-readme-example/src/evaluator.js

@rattrayalex
Copy link
Author

I'm salivating. Thanks!!

@rattrayalex
Copy link
Author

This issue should be closable now, though it would probably be good to have this documented in the Readme; all there is on this now is

By making the transform functions pure, you can test Getters easier, compose them easier, and nuclear can memoize calls to them, making Getter dependency resolution very performant.

@jordangarcia
Copy link
Contributor

Closed in #40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants