-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Documentation] How to memoize autotracked properties #19030
Comments
Hey @YoranBrondsema, thanks for opening up this issue! I agree that we should document caching via the cache primitive in the guides, this would be the current idiomatic way to do accomplish this with autotracking, and we actually discuss adding it to the guide this in the RFC. I haven't had a chance to write a guide yet, help would definitely be appreciated there! |
@pzuraq Thank you for your very helpful reply.
Great, I never knew about the addon. So I imagine that the
Cool. I'll work on it over the next few days and create a PR. Last thing: if I understand correctly, the |
Hi @pzuraq i also need this and tried using that polyfill you mentioned but it didn't work because of this bug: ember-polyfills/ember-cache-primitive-polyfill#3 Can I use the |
@urbany you can absolutely use the |
FYI there's now also a dedicated polyfill for So the options for caching autotracked properties as of today are:
I guess the choice is yours, until the Closing this for now as the main issue (documenting the memoization) has been resolved. |
I'm a long-time Ember user and it wasn't clear to me until recently that getters that use autotracking in Glimmer components are not memoized by default. In my interpretation of all the things that I read about autotracking in annoucements, blog posts and so on, autotracking was a drop-in replacement for
computed
: all the same benefits (including memoization) but without having to explicitly list the dependencies. Maybe I didn't read carefully enough, or maybe it wasn't communicated clearly enough.I realized that it wasn't when I started noticing degrading performance when I moved certain components in my application to Ember Octane. To my surprise, many getters were being recomputed even though the values of the getters they call didn't change.
For this reason, I can't wait for the @cached RFC to merge or to be available in a polyfill.
However, in the mean time, I still want to be able to enforce memoization for some properties in my Ember Octane components:
@computed
decorator compatible with autotracking? I don't mind if I need to explicitly list dependencies until the @cached RFC is merged. My priority now is to resolve the performance issues by avoiding unnecessary expensive recomputations.The text was updated successfully, but these errors were encountered: