In our previous article "XML-free Scala" we presented the removal of the native XML support from Scala with the two-fold objective to reduce the code size of the Scala standard library and to fasten the development of Scala software. We want now to further tailor the functionalities of the Scala standard library.
In this article we focus on the parallal collection framework which is the main addition to the Scala 2.9 software distribution (see the article "Revisited Scala Change History" for more details). More generally we want the claim "Scala is a scalable language" to also mean "Scala comes with a scalable library".
The Scala 2.9.1 API consists of the following Java archives and library packages:
Java archives | Library packages | ||
---|---|---|---|
scala-library.jar | 8635 KB | scala.actors |
Actor-based concurrency [1] |
scala.collection |
Collection framework with
mutable, immutable and parallel classes (eg. Seq ,
Map , Set , etc.) [2]
|
||
scala._ |
Combinator parsing, continuations, reflection, regular expressions, XML, etc. | ||
scala-dbc.jar | 298 KB | scala.dbc |
Database connection facilities |
scala-swing.jar | 838 KB | scala.swing |
Improved API to the Java Swing framework |
Since version 2.9 of the Scala distribution we have the unfortunate situation (see the article "Shrinking the Scala library code") where the size of the Scala standard library exceeds 8 MB !
Concretely we have the following two choices for further tailoring the Scala standard library:
This software distribution was generated from the SVN project scala-noxml (more details at the end of this article) and differs from the original Scala software distribution as follows:
scala.collection.parallel
, the parallel collection
framework, is not available anymore.
scala.actors
, the Actor library package, is made available
separately in file scala-actors.jar
.
sbaz
-ready.
This second software distribution differs from the original Scala software distribution as follows (more details at the end of this article):
scala.collection.parallel
, the parallel collection
framework, is made available as a separate Java archive,
scala-collection-parallel.jar
.
scala.actors
, the Actor library package, is made available
as a separate Java archive, scala-actors.jar
.
sbaz
-ready.
The generated Java archives are now:
Java archives | Library packages | |
---|---|---|
scala-library.jar |
5324 KB | scala._ |
scala-actors.jar |
404 KB | scala.actors |
scala-collection-parallel.jar |
1295 KB | scala.collection.parallel |
scala-dbc.jar |
298 KB | scala.dbc |
scala-swing.jar |
837 KB | scala.swing |
And the client code simply needs to specify the appropriate import clause to access the functionality of the library package (as for the Actor library), that is:
import scala.collection.parallel._
to use the parallel collection framework.
Please send your feedback or report issues directly to the author and not to the Scala project team.
The project modifications/additions are similar to those
described in our previous article "XML-free
Scala"; we added a few more project files and the two Ant targets
enable.par
and disable.par
.
The above project configuration makes it possible to build either the official Scala distribution or a Scala distribution with no parallel collection framework using the same code base.
Full Scala distribution
[2.9.x]$ ant dist-opt distpack-opt
Scala distribution with no parallel collection framework
[2.9.x]$ ant -f build-noxml.xml disable.par [2.9.x]$ ant -f build-noxml.xml dist-opt distpack-opt [2.9.x]$ ant -f build-noxml.xml enable.par
Scala distribution with no parallel collection framework and no native XML support
[2.9.x]$ ant -f build-noxml.xml disable.xml disable.par [2.9.x]$ ant -f build-noxml.xml dist-opt distpack-opt [2.9.x]$ ant -f build-noxml.xml enable.xml enable.par
The framework redesign consists of the following changes:
The following source files are moved to package
scala.collection.parallel
(where they actually belong):
parallel/CustomParallelizable.scala parallel/Parallelizable.scala parallel/Parallel.scala parallel/generic/CanCombineFrom.scala parallel/generic/GenericParCompanion.scala parallel/generic/GenericParTemplate.scala parallel/generic/HasNewCombiner.scala parallel/generic/ParFactory.scala parallel/generic/ParMapFactory.scala parallel/generic/ParSetFactory.scala
Some implicit conversions are added to file
parallel/package.scala
and give access to the
two methods par
and seq
:
package scala.collection //... package object parallel { //... implicit def iterable2ParIterable[A](col: Iterable[A]) = new Parallelizable[A, ParIterable[A]] { def seq = col protected[this] def parCombiner = ParIterable.newCombiner[A] } //.. (more implicits) implicit def cmHashset2ParHashSet[A](col: cm.HashSet[A]) = new Parallelizable[A, pm.ParHashSet[A]] { def seq = col override def par = new pm.ParHashSet(col.hashTableContents) protected[this] def parCombiner = pm.ParHashSet.newCombiner[A] } //... }
The chosen project configuration is similar to the one of project
scala-noxml
and makes it possible to build
either the official Scala distribution or
a Scala distribution with the standalone parallel collection framework
using the same code base.
Full Scala distribution
[scala-parlib]$ ant dist-opt distpack-opt
Scala distribution with standalone parallel collection framework
[scala-parlib]$ ant -f build-parlib.xml disable.par [scala-parlib]$ ant -f build-parlib.xml dist-opt distpack-opt [scala-parlib]$ ant -f build-parlib.xml enable.par