Description
I was just tracking down a performance issue and have across what seems to be the root of the issue.
I would type into an <input>
control whose value is managed by a Nuclear store, but the characters would take a long time to appear (150-200ms). This was the time from dispatching the action, until the render method was called.
Tracking this down I found that in notifyObservers
, some calls to evaluate()
were consistently taking a long time and not being cached.
This turned out to be related to a getter that looked like this (with about 2MB of data):
export let data = [
['query', 'data'],
(data) => {
return data ? data.toJS() : undefined;
}
];
Changing the return to the following fixed this (and other) performance issues:
return data;
I needed to add a call in a dependent getter to data.toJS()
though to compensate (this data is not used directly, but only as dependencies of other getters).
The problem seems to be that data.toJS()
returns a new object every time, so the getter is never cached. Moving it up the chain just "fixed" the problem by avoiding it though.
So my question is, what are the recommended practices for when and where to call toJS()
? I feel like components should only work with plain objects, so currently all my getters return plain objects, not ImmutableJS objects, but I'm not sure if that's how others are using Nuclear.
Thanks.