wix-incubator/accord

scala.js: Only adding accord into libraryDependencies adds +320kb after fullOptJS

Closed this issue · 4 comments

Hi.

I've tried to play around accord using getting-started page. I've added accord into deps like this:

  lazy val common = (crossProject.crossType( CrossType.Pure ) in file("common"))
    .settings(
      libraryDependencies ++= Seq(
        "com.wix"      %%% "accord-core" % "0.6.1"
      )
    )
    .jsConfigure(_ enablePlugins ScalaJSWeb)

  lazy val commonJS = common.js.settings(
    name := "commonJS",
    scalaVersion := "2.12.1"
  )

  lazy val someProj = project.in("someproj")
    .enablePlugins(ScalaJSPlugin, ScalaJSWeb)
    .dependsOn(commonJS)

...

Saved Build.scala.

And right after that, i've tried:

$ sbt
> project someProj
> fastOptJS
> fullOptJS

someproj-fastopt.js increased from 3916334 to 5604563 bytes.
someproj-opt.js increased from 686128 to 1023856 bytes. (+ 33%, WOW!).

Some useless js-generated code is here:

$ diff -pruN fastopt.js fastopt.js.big
...
+function $asArrayOf_Lorg_scalajs_testinterface_HTMLRunner$UI$Test(obj, depth) {
+  return (($isArrayOf_Lorg_scalajs_testinterface_HTMLRunner$UI$Test(obj, depth) || (obj === null)) ? obj : $throwArrayCastException(obj, "Lor
g.scalajs.testinterface.HTMLRunner$UI$Test;", depth))
+}
+function $is_Lorg_scalatest_Alerter(obj) {
+  return (!(!((obj && obj.$classData) && obj.$classData.ancestors.Lorg_scalatest_Alerter)))
+}
+function $as_Lorg_scalatest_Alerter(obj) {
+  return (($is_Lorg_scalatest_Alerter(obj) || (obj === null)) ? obj : $throwClassCastException(obj, "org.scalatest.Alerter"))
+}
+function $isArrayOf_Lorg_scalatest_Alerter(obj, depth) {
+  return (!(!(((obj && obj.$classData) && (obj.$classData.arrayDepth === depth)) && obj.$classData.arrayBase.ancestors.Lorg_scalatest_Alerter)))
+}
...

There are many scalatest stuff compiled-in.

But i do NOT ever added import com.wix.accord._ to any source, and NOT ever used any of accord classes. Only added accord to deps, nothing more.

I think, all this stuff must be stripped out by google-clojure optimizer, but it does not: ALL of scalatest code now compiled-in into final result.

Now, i've removed accord from deps, and everything gone back.
Tried with scala 2.11.8 and 2.12.1, with scalajs-0.6.13.

To reproduce the problem, use this shell code:

$ git clone https://github.com/scala-js/scalajs-tutorial
$ cd scalajs-tutorial
$ sbt fullOptJS

Let's check the filesize:
$ ls -l target/scala-2.12/scala-js-tutorial-opt.js
-rw-r--r-- 1 user user 10007 ...
So, it is less than 10 KiB.

Add accord into deps, with newlines:

$ cat >> build.sbt << EOF

libraryDependencies += "com.wix" %%% "accord-core" % "0.6.1"
EOF

Again, rebuild and look for filesize...
$ sbt fullOptJS
$ ls -l target/scala-2.12/scala-js-tutorial-opt.js
-rw-r--r-- 1 user user 548026 ...

More than +500 KiB by now...

Issue confirmed and reproduced. Looking into it.

Well, this is embarrassing: evidently the problem is a simple, careless dependency on ScalaTest from the accord-api module, which has been around since 0.5 or so (diff). Surprisingly enough, no-one noticed up until now :-/

I'll be pushing a change shortly. I don't think this is worth its own release, since it can be easily worked around with exclusions:

// Before exclusion...

> set libraryDependencies += "com.wix" %%% "accord-core" % "0.6.1"
[info] Defining *:libraryDependencies
[info] The new value will be used by *:allDependencies, *:dependencyPositions
[info] Reapplying settings...
[info] Set current project to Scala.js Tutorial (in build file:/Users/tomerga/dev/scalajs-tutorial/)
> dependencyTree
[info] Updating {file:/Users/tomerga/dev/scalajs-tutorial/}scalajs-tutorial...
[info] Resolving org.eclipse.jetty#jetty-continuation;8.1.16.v20140903 ...
[info] downloading https://repo1.maven.org/maven2/com/wix/accord-core_sjs0.6_2.12/0.6.1/accord-core_sjs0.6_2.12-0.6.1.jar ...
[info] 	[SUCCESSFUL ] com.wix#accord-core_sjs0.6_2.12;0.6.1!accord-core_sjs0.6_2.12.jar (778ms)
[info] downloading https://repo1.maven.org/maven2/com/wix/accord-api_sjs0.6_2.12/0.6.1/accord-api_sjs0.6_2.12-0.6.1.jar ...
[info] 	[SUCCESSFUL ] com.wix#accord-api_sjs0.6_2.12;0.6.1!accord-api_sjs0.6_2.12.jar (368ms)
[info] Done updating.
[info] scala-js-tutorial:scala-js-tutorial_sjs0.6_2.12:0.1-SNAPSHOT [S]
[info]   +-be.doeraene:scalajs-jquery_sjs0.6_2.12:0.9.1 [S]
[info]   | +-org.scala-js:scalajs-dom_sjs0.6_2.12:0.9.1 [S]
[info]   | | +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   | | +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   | |
[info]   | +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   | +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   |
[info]   +-com.wix:accord-core_sjs0.6_2.12:0.6.1 [S]
[info]   | +-com.wix:accord-api_sjs0.6_2.12:0.6.1 [S]
[info]   | | +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   | | +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   | | +-org.scalatest:scalatest_sjs0.6_2.12:3.0.0 [S]
[info]   | |   +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   | |   +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   | |   +-org.scala-js:scalajs-test-interface_2.12:0.6.13 [S]
[info]   | |   | +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   | |   | +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   | |   |
[info]   | |   +-org.scala-lang:scala-reflect:2.12.1 [S]
[info]   | |   +-org.scalactic:scalactic_sjs0.6_2.12:3.0.0 [S]
[info]   | |     +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   | |     +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   | |     +-org.scala-lang:scala-reflect:2.12.1 [S]
[info]   | |
[info]   | +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   | +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   | +-org.scalamacros:resetallattrs_2.12:1.0.0 [S]
[info]   |
[info]   +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   +-org.webjars:jquery:2.1.4
[info]
[success] Total time: 3 s, completed Dec 25, 2016 6:53:56 PM

// After exclusion...

> set libraryDependencies += "com.wix" %%% "accord-core" % "0.6.1" excludeAll(ExclusionRule(organization = "org.scalatest"))
[info] Defining *:libraryDependencies
[info] The new value will be used by *:allDependencies, *:dependencyPositions
[info] Reapplying settings...
[info] Set current project to Scala.js Tutorial (in build file:/Users/tomerga/dev/scalajs-tutorial/)
> dependencyTree
[info] Updating {file:/Users/tomerga/dev/scalajs-tutorial/}scalajs-tutorial...
[info] Resolving org.eclipse.jetty#jetty-continuation;8.1.16.v20140903 ...
[info] Done updating.
[info] scala-js-tutorial:scala-js-tutorial_sjs0.6_2.12:0.1-SNAPSHOT [S]
[info]   +-be.doeraene:scalajs-jquery_sjs0.6_2.12:0.9.1 [S]
[info]   | +-org.scala-js:scalajs-dom_sjs0.6_2.12:0.9.1 [S]
[info]   | | +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   | | +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   | |
[info]   | +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   | +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   |
[info]   +-com.wix:accord-core_sjs0.6_2.12:0.6.1 [S]
[info]   | +-com.wix:accord-api_sjs0.6_2.12:0.6.1 [S]
[info]   | | +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   | | +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   | |
[info]   | +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   | +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   | +-org.scalamacros:resetallattrs_2.12:1.0.0 [S]
[info]   |
[info]   +-org.scala-js:scalajs-library_2.12:0.6.13 (evicted by: 0.6.14)
[info]   +-org.scala-js:scalajs-library_2.12:0.6.14 [S]
[info]   +-org.webjars:jquery:2.1.4
[info]
[success] Total time: 1 s, completed Dec 25, 2016 6:55:41 PM