Does anyone have any advice for how to reduce the ...
# compose-web
d
Does anyone have any advice for how to reduce the size of my final JS output? I'm worried I might be writing my code in a way that accidentally prevents DCE from working without realizing it, for example.
(I'm writing both a C4W app and some libraries -- not sure if the way I'm writing the libraries could be improved)
A great place to start would be if I could get some sort of report about what code is being kept alive vs what's getting eliminated. I'm paranoid some stuff is sticking around that I don't expect.
o
I recall there was a compiler flag to report DCE for kjs. I tried to find it quickly, but it's inconvenient to do on the smartphone. I'll look for it later on a laptop.
d
No rush! Thanks! Now that I know there's a compiler flag, I can look into it too later.
o
d
Thank you for following up!
b
There is a compiler option
-Xir-dce-print-reachability-info
Then DCE will print to stdout what and why was marked as reachable.
Copy code
from.fqn -> to.fqn // comment
s
@bashor @David Herman I struggle to make it working on a basic Compose for Web project. I configured:
Copy code
js(IR) {
	browser()
	binaries.executable()
	compilations.all {
		kotlinOptions {
			freeCompilerArgs += "-Xir-dce-print-reachability-info"
			freeCompilerArgs.forEach(::println)
		}
	}
}
Then I run
./gradlew clean compileProductionExecutableKotlinJs
but I see no reachability info on the standard output. What did I miss?
d
(Ah glad to hear you're digging into this -- I'm still a bit backlogged and never got a chance)
s
Ok so let's wait Zalim feedback.
b
AFAIR
compilations.all {
inside `js`/`wasm` block affects only first fase of compilation — klib generation. Also, it turned out there is a bug so if you use
-Xir-dce-print-reachability-info
you also need restore
-Xir-dce
(cc @Ilya Goncharov [JB]) Final snippet could look like:
Copy code
tasks.withType<org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile>().configureEach {
    kotlinOptions.freeCompilerArgs += listOf(
        "-Xir-dce", 
        "-Xir-dce-print-reachability-info"
    )
}
you find printed result in
kotlin-daemon.*.log
inside your
$TMPDIR
alternatively you can pass
-Pkotlin.compiler.execution.strategy=in-process
to the gradle so you will get compiler stdout right into your terminal
s
Ok thanks!
Tested, it works as expected with this configuration.