Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debox.Map.contains boxes (!) #19

Open
denisrosset opened this issue Oct 21, 2014 · 5 comments
Open

debox.Map.contains boxes (!) #19

denisrosset opened this issue Oct 21, 2014 · 5 comments

Comments

@denisrosset
Copy link

debox.Map[Int, AnyRef].contains(key: Int) boxes, I do not know exactly why, but the performance suffers quite a bit:

untitled

This is on Scala 2.11.2. I wonder if it is the inner tail recursive method that causes specialization to fail.

@non
Copy link
Owner

non commented Oct 21, 2014

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 :/

@denisrosset
Copy link
Author

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.

@denisrosset
Copy link
Author

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.

@denisrosset
Copy link
Author

See #20.

@denisrosset
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants