medikoo / memoizee

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

Memory optimization #34

Open medikoo opened 9 years ago

medikoo commented 9 years ago

Currently for each memoized function there are few functions created, that affects memory badly when our configration deals with thousands of memoized instances. It'll be much more optimal to rely on prototype inheritance model in that case

puzrin commented 8 years ago

As far as i remember, perf problem also can happen on thousands of setTimeout(). Solution is to have a list of deadlines, and scan it with single timer.

medikoo commented 8 years ago

@puzrin true, it's a great tip

puzrin commented 8 years ago

For setTimeout it's possible to use the same function if you pass params:

.setTimeout(fn, delay, param1, param2, ...)

In browser that will require patch for IE <= 9 https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout

medikoo commented 8 years ago

For setTimeout it's possible to use the same function if you pass params:

I'm not convinced it'll bring anything noticeable in terms of performance. I'm sure it's more important to produce less setTimeout calls (decide on some threshold) as you suggested before

puzrin commented 8 years ago

https://github.com/nodejs/node/blob/master/lib/timers.js#L283 there are unofficial enroll/unenroll functions. Can be used instead of setTimeout/clearTimeout. But i'm not sure this hack is really needed.