DEV Community

Discussion on: Memoization in Javascript

Collapse
 
gerardolima profile image
Gerardo Lima • Edited

I'd recommend using a Map or a WeakMap as memo, instead of object. Also, I'd recommend using some sort of lock to avoid executing the underlying "expensive" function while another instance is running for the same parameters.

Collapse
 
anishkumar profile image
Anish Kumar • Edited

Yes. WeakMap would be a good choice if you are using objects as keys, it would facilitate better garbage collection in this case. If your keys are strings, using object should be fine.