medikoo / memoizee

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

feat: support EsModules #143

Closed aminya closed 1 week ago

aminya commented 2 weeks ago

This adds support for EsModules to Memoizee. This is a step towards the modernization of this library. The old Node 0.12 support is maintained via Babel, and thus these changes are fully backwards compatible.

When ' ESM ' is used, the main memoizee function loads the extensions asynchronously via dynamic imports. This helps prevent the bundling of unused code in the browsers.

31st Aug 2024 benchmarks:

1:    13ms  Memoizee (object mode)
2:     2ms  Memoizee (primitive mode)
3:     2ms  Underscore
4:     3ms  Lo-dash
5:     7ms  Memoizee (primitive mode) LRU (max: 1000)
6:     9ms  Memoizee (object mode)    LRU (max: 1000)
7:     5ms  lru-cache                 LRU (max: 1000)
8:     5ms  secondary-cache           LRU (max: 1000)
medikoo commented 1 week ago

@aminya great thanks for the effort, but at this point I do not plan to refactor this package into ES modules.

I believe this package is also perfectly accessible from ES modules context.

Ideally such changes, before taking implementation effort should be first consulted on issue level

aminya commented 1 week ago

No problem. I assumed that this repo will not be open to modernization given the number of polyfills that are imported directly. I'll create a hard fork then.

aminya commented 1 week ago

Here's the fork link for those interested. I'll probably rename and publish the modernized package on npm soon. It will be API-compatible with memoizee, and will support all the old platforms via Babel. https://github.com/aminya/memoizee/