medikoo / memoizee

Complete memoize/cache solution for JavaScript
ISC License
1.73k stars 61 forks source link

Allow interim reset of profile data #74

Open wan54 opened 7 years ago

wan54 commented 7 years ago

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

medikoo commented 7 years ago

@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.

wan54 commented 7 years ago

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
medikoo commented 7 years ago

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 commented 7 years ago

I was questioning why the initial hit increases in the subsequent clear and call.

On 16 Mar 2017, at 18:17, Mariusz Nowak notifications@github.com wrote:

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 (?)

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub, or mute the thread.

medikoo commented 7 years ago

@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

wan54 commented 7 years ago

Yes that'd be great. Thanks.

On 17 Mar 2017, at 19:26, Mariusz Nowak notifications@github.com wrote:

@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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

medikoo commented 7 years ago

Yes that'd be great. Thanks.

Ok Iet's make this issue about that. I'll leave it open until it's addressed