Arraybuffer specialization

153 views
Skip to first unread message

Pedro Larroy

unread,
Jan 26, 2015, 4:59:22 AM1/26/15
to scala-user

Hi

Are there any plans to specialize arraybuffer to avoid boxing? I have been starting to use arraybuilder for this reason but I wonder if there is some reason that prevents specializing arraybuffer in the standard library.

Related issue:

https://issues.scala-lang.org/plugins/servlet/mobile#issue/SI-4596

Pedro.

Vlad Ureche

unread,
Jan 26, 2015, 7:54:41 AM1/26/15
to Pedro Larroy, scala-user
The main reason Scala collections are not specialized is the bytecode size it would generate (at least a 10x increase of the Scala library size).

Instead of specialization, I would recommend giving miniboxing [1] a try. Several collections have been compiled with miniboxing, such as linked lists [2], vectors [3] [4] and streams [5] with really good results.
If you're interested in giving it a shot, I can code a miniboxing-specialized ArrayBuffer for you.

HTH,
Vlad

[1] scala-miniboxing.org
[2] scala-miniboxing.org/example_linkedlist.html
[3] io.pellucid.com/blog/optimistic-respecialization-attempt-6
[4] github.com/nicolasstucki/scala-rrb-vector/tree/adding-miniboxing
[5] github.com/miniboxing/miniboxing-plugin/issues/146

Pedro.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oliver Ruebenacker

unread,
Jan 26, 2015, 8:24:56 AM1/26/15
to Vlad Ureche, Pedro Larroy, scala-user

     Hello,

  How about offering specialized versions of standard collections as extension libraries? Seems like it should be easy to produce and fulfill a clear need.

     Best, Oliver
--
Oliver Ruebenacker
Solutions Architect at Altisource Labs
Be always grateful, but never satisfied.

Vlad Ureche

unread,
Jan 26, 2015, 10:22:08 AM1/26/15
to Oliver Ruebenacker, Pedro Larroy, scala-user

2015-01-26 14:24 GMT+01:00 Oliver Ruebenacker <cur...@gmail.com>:

  How about offering specialized versions of standard collections as extension libraries? Seems like it should be easy to produce and fulfill a clear need.


Good question! So far, most attempts were exploratory, seeing how well things work and what transformations are necessary.
But now that the miniboxing plugin is quite stable, we should really think about developing collections based on it.

I will start working on this after version 0.4 of the plugin is ready.

Cheers,
Vlad

Pedro Larroy

unread,
Jan 26, 2015, 10:45:43 AM1/26/15
to Vlad Ureche, scala-user
Hi Vlad

This is clear, but specializing only ArrayBuffer might not be so much of a size increase wouldn't it? I understand that then the question arises about specializing some collections and not others. Fair enough, but arraybuffer is such a basic data structure that might justify the exception in my opinion.

Thanks.
Pedro.

Erik Osheim

unread,
Jan 26, 2015, 12:05:56 PM1/26/15
to Pedro Larroy, scala-user
On Mon, Jan 26, 2015 at 10:59:13AM +0100, Pedro Larroy wrote:
> Are there any plans to specialize arraybuffer to avoid boxing? I have been
> starting to use arraybuilder for this reason but I wonder if there is some
> reason that prevents specializing arraybuffer in the standard library.

If you're interested, give debox.Buffer[A] a try:

https://github.com/non/debox#buffer

-- Erik

Pedro Larroy

unread,
Jan 26, 2015, 12:32:56 PM1/26/15
to Erik Osheim, scala-user
Thanks, I did, and I am aware of those projects. The question was more if ArrayBuffer should be specialized in the standard library by default.

Thanks again for the suggestions.

Vlad Ureche

unread,
Jan 26, 2015, 6:01:00 PM1/26/15
to Pedro Larroy, scala-user

2015-01-26 16:43 GMT+01:00 Pedro Larroy <pedro.lar...@gmail.com>:

This is clear, but specializing only ArrayBuffer might not be so much of a size increase wouldn't it? I understand that then the question arises about specializing some collections and not others. Fair enough, but arraybuffer is such a basic data structure that might justify the exception in my opinion.

In general, specializing a single class in the library doesn't bring any benefit, as most of its methods are implemented in traits. On the contrary, passing values across the specialized/non-specialized boundary kills performance, as it boxes values just to unbox them later, creating mountains of garbage. That's the price you're paying for having all the nice convenience methods uniformly across all collections.

HTH,
Vlad
Reply all
Reply to author
Forward
0 new messages