bertramdev / asset-pipeline

The core implementation of the asset pipeline for the jvm
193 stars 92 forks source link

Asset Pipeline 40x larger file size - 4.3.0 requires and additional 55.81 MB compared to 3.4.7 #328

Closed codeconsole closed 4 months ago

codeconsole commented 1 year ago

Are all these dependencies necessary in the production jar? If not, what is the best way to exclude them?

Asset Pipeline 4.3.0

+--- com.bertramlabs.plugins:asset-pipeline-grails:4.3.0
    \--- com.bertramlabs.plugins:asset-pipeline-core:4.3.0
         +--- org.graalvm.sdk:graal-sdk:22.0.0.2
         +--- org.graalvm.js:js:22.0.0.2
         |    +--- org.graalvm.regex:regex:22.0.0.2
         |    |    \--- org.graalvm.truffle:truffle-api:22.0.0.2
         |    |         \--- org.graalvm.sdk:graal-sdk:22.0.0.2
         |    +--- org.graalvm.truffle:truffle-api:22.0.0.2 (*)
         |    \--- org.graalvm.sdk:graal-sdk:22.0.0.2
        +--- org.graalvm.js:js-scriptengine:22.0.0.2
         |    \--- org.graalvm.sdk:graal-sdk:22.0.0.2
         \--- org.slf4j:slf4j-api:1.7.28 -> 1.7.36

Asset Pipeline 3.4.7

+--- com.bertramlabs.plugins:asset-pipeline-grails:3.4.7
    \--- com.bertramlabs.plugins:asset-pipeline-core:3.4.7
         \--- org.slf4j:slf4j-api:1.7.28 -> 1.7.36
rlconst commented 1 year ago

The problem is in https://github.com/bertramdev/asset-pipeline/commit/1d9ac7ff9d091b61070f6a912aad91743d1e11e7

Probably https://github.com/oracle/graaljs should be enough instead of full graal development kit designed for building languages and native compilation. These documents https://www.graalvm.org/latest/reference-manual/js/#interoperability-with-java ans https://www.graalvm.org/latest/reference-manual/js/RunOnJDK/ show different dependencies required to execute js

Also relevant discussing https://github.com/oracle/graal/issues/287

We can consider using rhino which is ~1mb dependency https://github.com/mozilla/rhino or ~2mb https://github.com/openjdk/nashorn

davydotcom commented 4 months ago

neither rhino nor nashorn are viable on more modern jdks and babel.js will not run within them. graal is necessary. graal-sdk is there for older versions of java runtime (i.e. java8)

codeconsole commented 4 months ago

@davydotcom if the assets are compiled at build time, why are all these dependencies needed during runtime on a production jar?

+--- com.bertramlabs.plugins:asset-pipeline-grails:4.3.0
|    \--- com.bertramlabs.plugins:asset-pipeline-core:4.3.0
|         +--- org.graalvm.sdk:graal-sdk:22.0.0.2
|         +--- org.graalvm.js:js:22.0.0.2
|         |    +--- org.graalvm.regex:regex:22.0.0.2
|         |    |    \--- org.graalvm.truffle:truffle-api:22.0.0.2
|         |    |         \--- org.graalvm.sdk:graal-sdk:22.0.0.2
|         |    +--- org.graalvm.truffle:truffle-api:22.0.0.2 (*)
|         |    \--- org.graalvm.sdk:graal-sdk:22.0.0.2
|         +--- org.graalvm.js:js-scriptengine:22.0.0.2
|         |    \--- org.graalvm.sdk:graal-sdk:22.0.0.2
|         \--- org.slf4j:slf4j-api:1.7.28 -> 1.7.36

These 2 dependencies add 57M to the final jar.

8.5M    truffle-api-22.0.0.2.jar
 48M    js-22.0.0.2.jar
codeconsole commented 4 months ago

Here is my workaround which should not be necessary:

configurations {
    //  ...
    runtimeOnly.exclude group: "org.graalvm.js"
    runtimeOnly.exclude group: "org.graalvm.sdk"    
}

Which takes down website.jar from 146M to 86M

rlconst commented 4 months ago

@davydotcom I agree with @codeconsole. Full graal SDK should be excluded from runtime, it's unnecessary bloat for grails app runtime

rlconst commented 4 months ago

@codeconsole to make grails runnable in dev mode I had to include

bootRun { task ->
    dependencies {
        implementation "org.graalvm.polyglot:polyglot:24.0.2"
        implementation "org.graalvm.polyglot:js:24.0.2"
    }
}
davydotcom commented 4 months ago

@rlconst i think i fixed this. the gradle plugin was not up to date in the gradle plugin publish. asset-pipeline-gradle:4.5.1 should fix it. This auto injects those dependencies on the bootRunt ask