Its a great talk on the details of implement of the two data types.
What I found interesting was that Michał emphasised that a lot of work has gone on to make
deftype really performant in Clojurescript.
To test the performance, I used the scaffolding I had worked on and described here.
Foo2 using a
defrecord. Here is the code:
I tested the performance of following three things:
which are the idiomatic ways of data access for the three data types.
All results are for Chrome 52.0.2734.0 canary (64-bit) on Mac OS X:
So in this example, field access for a
deftype is 4 times faster than that for
defmethod and 7 times faster than a normal
The speed of
Now onto function invocation for the two datatypes.
I tested the performance of following two things:
(add-num f1 1)
(add-num f2 1)
|deftype function call||1.3490893960300394e-8|
|defmethod function call||1.519495239675906e-8|
The results here are mixed.
So we need to look at the definition of
The key thing is if the first argument to
add_num is non-null and it’s prototype has a method called
bench$core$IAdd$add_num$arity$2 defined, then it is called with the two argument.
Looking at the code for
Foo2, we see that the method is defined.
The function call for the two datatypes looks exactly the same. This explains the similarity in performance of the two.