-
- Downloads
[perf] Better CLJC memoization; bounded strategy, fast versions (#46199)
Expands and refactors `metabase.util.memoize` to support better cross-platform memoization. **Better basic memoization** Use `clojure.core.memoize/memo` (and its clone in CLJS) rather than `clojure.core/memoize` for the "everything forever" strategy. **Bounded memoization** There are a few places (eg. `u/kebab-case-en`) where we want zero-overhead *hits* and expect the input space to be fixed. To guard against runaway memory usage, this **bounded** strategy dumps the entire cache when it overflows. It logs an INFO level note when that happens - the intent here is that the threshold should never actually get hit! **Fast JVM versions** In the special case where the function to memoize takes exactly 1 argument which is a valid map key, we can use `ConcurrentHashMap.computeIfAbsent` as the basis of the cache and have much less overhead. `fast-memo` and `fast-bounded` implement this in CLJ; in CLJS they just call `memo` and `bounded`.
Showing
- .clj-kondo/config.edn 3 additions, 1 deletion.clj-kondo/config.edn
- src/metabase/lib/js/metadata.cljs 2 additions, 8 deletionssrc/metabase/lib/js/metadata.cljs
- src/metabase/util.cljc 8 additions, 5 deletionssrc/metabase/util.cljc
- src/metabase/util/memoize.clj 0 additions, 12 deletionssrc/metabase/util/memoize.clj
- src/metabase/util/memoize.cljc 83 additions, 0 deletionssrc/metabase/util/memoize.cljc
- src/metabase/util/memoize/impl/bounded.cljc 32 additions, 0 deletionssrc/metabase/util/memoize/impl/bounded.cljc
- src/metabase/util/memoize/impl/js.cljs 42 additions, 3 deletionssrc/metabase/util/memoize/impl/js.cljs
- test/metabase/util/memoize_test.cljc 75 additions, 0 deletionstest/metabase/util/memoize_test.cljc
src/metabase/util/memoize.clj
deleted
100644 → 0
src/metabase/util/memoize.cljc
0 → 100644
src/metabase/util/memoize/impl/bounded.cljc
0 → 100644
test/metabase/util/memoize_test.cljc
0 → 100644
Please register or sign in to comment