https://kotlinlang.org logo
#compose-web
Title
# compose-web
d

David Herman

02/04/2023, 4:33 PM
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

Oleksandr Karpovich [JB]

02/04/2023, 9:23 PM
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

David Herman

02/05/2023, 12:30 AM
No rush! Thanks! Now that I know there's a compiler flag, I can look into it too later.
o

Oleksandr Karpovich [JB]

02/05/2023, 6:40 AM
d

David Herman

02/06/2023, 5:17 PM
Thank you for following up!
b

bashor

02/16/2023, 8:18 PM
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

sdeleuze

02/27/2023, 7:41 PM
@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

David Herman

02/27/2023, 7:43 PM
(Ah glad to hear you're digging into this -- I'm still a bit backlogged and never got a chance)
s

sdeleuze

02/27/2023, 7:44 PM
Ok so let's wait Zalim feedback.
b

bashor

02/27/2023, 11:04 PM
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

sdeleuze

02/28/2023, 4:45 AM
Ok thanks!
Tested, it works as expected with this configuration.
35 Views