js-ceramic icon indicating copy to clipboard operation
js-ceramic copied to clipboard

chore: Make memoization slightly faster and more reliable

Open ukstv opened this issue 3 years ago • 2 comments

This is not related to any of the ongoing work. Feel free to consider that the lowest priority.

@stbrody's hypothesis about memoization changing shape of a StreamID instance caught my attention. That should not affect Jest snapshots, but technically memoization modifies the instance.

Apparently, there is a better way to handle memoization. It is 20%-40% faster, smaller(802B vs 1.4kB now). It does not pollute the instances thanks to WeakMap usage.

Also, it could support LRU for memoization, so we could use it more widely.

ukstv avatar Jun 16 '22 20:06 ukstv

the change to js-ceramic isn't really signficant, the real thing that needs review is the implementation of the mapmoize package: https://github.com/ukstv/mapmoize/blob/main/src/index.ts. (note @ukstv the NPM repo doesn't link to the source code, I had to find it on your github directly)

I don't really feel equipped to review the mapmoize library implementation. Maybe @zachferland or @oed do?

stbrody avatar Jun 17 '22 20:06 stbrody

@stbrody Thanks. Added a link to the repo to package.json

TIL: Apparently shortcut like "repository": "npm/npm" is not displayed on npm package page.

ukstv avatar Jun 21 '22 10:06 ukstv

Folks @stbrody @willex @stephhuynh18 any news on approval?

The merge is obviously conditional on conflict resolution.

ukstv avatar Nov 04 '22 14:11 ukstv

Folks @stbrody @willex @stephhuynh18 any news on approval?

The merge is obviously conditional on conflict resolution.

Can you open a pr for the implementation of mapMemoize? That's actually the important and complex part.

stbrody avatar Nov 04 '22 14:11 stbrody

@stephhuynh18 Thank you! @stbrody Good to go?

ukstv avatar Nov 29 '22 17:11 ukstv