debox
debox copied to clipboard
debox.Map.contains boxes (!)
debox.Map[Int, AnyRef].contains(key: Int) boxes, I do not know exactly why, but the performance suffers quite a bit:
This is on Scala 2.11.2. I wonder if it is the inner tail recursive method that causes specialization to fail.
So, this is actually a specialization failure. If you had a debox.Map[Int, Int]
you would not see this problem.
Currently it seems like mixed primitive/Object specializations fail. There was a feature awhile ago ("AnyRef specialization") which was designed to solve this exact problem. But it doesn't seem to be working.
I'm looking into this but it's possible that Debox can't fix the problem :/
Correct. I think I found the culprit: the specialized annotation (which is performed on the value type) without any arguments involves primitives, excluding AnyRef.
See https://github.com/scala/scala/blob/v2.10.4/src/library/scala/specialized.scala#L1
Thus for the pair (Int, AnyRef), the only available variant is (AnyRef, AnyRef). I'm trying to include explicitly AnyRef for the value type and see if it boxes. Will keep you informed.
No, even when specializing on (Int, AnyRef) for both A and B, it still boxes, even when writing Map[Int, AnyRef] and not a subtype of AnyRef.
Removing the specialization on B, the boxing disappears.
I will propose a hackish solution in a PR.
See #20.
I found a solution for that problem, and ended up implementing a new library for fast data structures: https://github.com/denisrosset/metal .
Metal provides data structures that can operate on a mix of primitive/AnyRef types such a Map2[Int, String, Long]
, with the same functionality of scala.collection.Map[Int, (String, Long)]
, however without boxing.
However, one drawback of Metal is that it is heavily based towards array-based data structures. For example, linked lists are difficult to implement on its framework.