diff --git a/CHANGES.md b/CHANGES.md index 1b78fc4..d6908c3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ## 0.11.1 (unreleased) * More efficient inline caching for Clojure version, now inline caching is always within 5% of manually precompiled code +* Significant performance improvement for ALL transform on maps for Clojure version (25% on simple benchmarks) ## 0.11.0 * New `path` macro does intelligent inline caching of the provided path. The path is factored into a static portion and into params which may change on each usage of the path (e.g. local parameters). The static part is factored and compiled on the first run-through, and then re-used for all subsequent invocations. As an example, `[ALL (keypath k)]` is factored into `[ALL keypath]`, which is compiled and cached, and `[k]`, which is provided on each execution. If it is not possible to precompile the path (e.g. [ALL some-local-variable]), nothing is cached and the path will be compiled on each run-through. diff --git a/src/clj/com/rpl/specter/impl.cljx b/src/clj/com/rpl/specter/impl.cljx index 1012908..4f569ab 100644 --- a/src/clj/com/rpl/specter/impl.cljx +++ b/src/clj/com/rpl/specter/impl.cljx @@ -553,7 +553,15 @@ (doall (map next-fn structure)) (map? structure) - (->> structure (r/map vec) (r/map next-fn) (into empty-structure)) + ;; reduce-kv is much faster than doing r/map through call to (into ...) + (reduce-kv + (fn [m k v] + (let [[newk newv] (next-fn [k v])] + (assoc m newk newv) + )) + empty-structure + structure + ) :else (->> structure (r/map next-fn) (into empty-structure))