reduxjs / reselect

Selector library for Redux
MIT License
19.03k stars 671 forks source link

LRU implementation with hashmap and doubly linked list #701

Closed kuldeepsinghborana closed 6 months ago

netlify[bot] commented 6 months ago

Deploy Preview for reselect-docs canceled.

Name Link
Latest commit af114daf0fd9e6c0f5857382b598c30269c97e44
Latest deploy log https://app.netlify.com/sites/reselect-docs/deploys/65d39e469dc6de0008edd250
codesandbox-ci[bot] commented 6 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

EskiMojo14 commented 6 months ago

this doesn't seem to use the equality function?

kuldeepsinghborana commented 6 months ago

this doesn't seem to use the equality function?

@EskiMojo14 Yes, the equality function can not be used with a hashmap, we need to iterate throgh the all values which will not give us any advantage our the existing memoiser

markerikson commented 6 months ago

@kuldeepsinghborana yeah, that's a problem, and that's what i was pointing to in the issue thread. We rely on equality checks, not a single key.

kuldeepsinghborana commented 6 months ago

@markerikson @EskiMojo14 @aryaemami59 Can we create a new memoizer that takes a keyGen (key generator) function as an argument? The default keyGen function would convert the supplied argument into a JSON string. Subsequently, our cache Map would utilize this string as a key.

To enhance predictability in the JSON string, we can implement key sorting, ensuring that keys are consistently ordered for every object.

markerikson commented 6 months ago

@kuldeepsinghborana no, just converting values into a string is potentially very expensive. Imagine doing a JSON.stringify() on the entire Redux state for a large app.

markerikson commented 6 months ago

array.join() isn't going to help either. {a: 1} and {a: 2} are both going to stringify to "[object Object]", which is not unique.