I profiled it and found out much of the time is spent inside
TypeInfo.opEquals being called from tryPutting. So I tried
replacing "!=
typeid" in tryPutting with "!is typeid". That brought the time
from 2.8 s
down to 0.12 on my machine. I don't know if that is the proper
solution,
since I don't know if typeid can ever return two TypeInfo
objects that
aren't the same but are equal (I haven't used typeid and
TypeInfo much
before). The fib function here does return correct result
after doing that,
though.
Wow! Now that's an impressive improvement. If TypeInfo
instances are unique
for every type, then we should be good to go!
I've tried Dmitry's fork now (he optimized opArithmetic to not do
as many calls to fptr) and it's even a little faster (1.01 s for
100000 iterations). Replacing != with !is in Dmitry's fork speeds
it up a little bit more (0.935 s for 100000 iterations).