Allow interim reset of profile data
wan54 opened this issue · comments
EDIT: This issue originally was false bug report, but ended as a request for ability to reset profile numbers
calling clear() on a memoized function doesn't seem to work.
example:
let fn = null;
export const exportedFn = (dataArg) => {
fn = fn || memoize((object) => {
// code that uses object and dataArg; fn will be called recursively
}, {serializer: (args) => JSON.stringify(args[0])})
return fn;
};
setInterval(() => {
// fn.clear(); // does not clear
fn = null; // an alternative to clear() however the next fn invocation increases the Initial hit size by double, more or less, reported by memoize/profile
}, 30000);
any ideas why clear() does not have any effect?
Thanks
@wan54 your example seems incomplete. Can you provide a complete test case, that exposes eventual issue?
In what you've shown, many things can happen.. e.g. external module may call exportedFn
few times, while setInterval
will clear cache only to last one generated.
You're right. It's because only the last one the issue. I'm clearing as soon as fn() finishes. Thanks.
Is it expected though that the next fn invocation increases the Initial hit size
1. fn() call
Init Cache %Cache
864 622 41.86
2. fn.clear()
3. fn() call
Init Cache %Cache
1641 1167 41.56
4. fn.clear()
5. fn() call
Init Cache %Cache
2418 1712 41.45
With clear
you clear the cache totally, and you go back to initial state, so it's normal that next invocations will produce similar profile output as first one. Unless I don't understand something (?)
@wan54 you mean, why counter was not reset after clear?
The profile functionality is global, it covers all memoized functions registered in a process, and doesn't have any reset counter function. Would you like to see it? I think it makes sense to add it
Yes that'd be great. Thanks.
Ok Iet's make this issue about that. I'll leave it open until it's addressed