robertluo / fun-map

a map blurs the line between identity, state and function

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slow performance

mjmeintjes opened this issue · comments

When using the fun-map in a function that gets called a lot, the performance seems to be much slower than I would expect (about a factor of 10x).

I ran a profiler on the code, and I suspect it is the call to satifies? that is the problem, here:

(satisfies? ValueWrapper o))
.

Here is a good explanation of the problems of satisfies? - https://bsless.github.io/datahike-datalog-parser/

Not sure if this is something that you'd be interested in looking at. It could be that this will be solved automatically in future version of clojure, as there is an open ticket (https://clojure.atlassian.net/browse/CLJ-1814).

An option would be to add a -wrapped? function to the ValueWrapper protocol, and then implement the ValueWrapper protocol for Object.

For example:

(extend-type Object
  ValueWrapper
  (-wrapped? [_] false))

(extend-type nil
  ValueWrapper
  (-wrapped? [_] false))