Why Kotlin native generated executable is larger than the equivalent in rust


Considering both Kotlin-native and Rust are based on LLVM, I expect there output and performance to be close!

So created 2 simple Hello World! with kotlin and rust


fun main() {
    println("Hello, world!")


fn main() {
    println!("Hello, world!");

Then generated the executable files for bot using:
kotlinc-native main.kt for kotlin and cargo build for rust

Then checked the executables/binary using the below:

ls -S -lh | awk '{print $5, $9}'

and found that the file generated by kotlin native is 1.48X the file generated by rust.

Any idea why this variance!

enter image description here

Moreover Rust can be optimized to be smaller, Is there something simliar in Kotlin native?

Initial setup:

$ cargo new hello_world

Build with:
$ cargo build

:point_right:t2: 589,004 bytes

Optimization Step 1:

Build with:
$ cargo build --release

:point_right:t2: 586,028 bytes

Optimization Step 2:

Change contents of main.rs to:

use std::alloc::System;

static A: System = System;

fn main() {
   println!("Hello, world!");

:point_right:t2: 335,232 bytes

Optimization Step 3:

Add …

lto = true

to Cargo.toml .

:point_right:t2: 253,752 bytes

Optimization Step 4:

Strip executable via …
$ strip target/release/hello_world

:point_right:t2: 177,608 bytes

So, we ended up having the file generated by kotlin native is 4.87X (~ 5X) the file generated by rust


I guess the stdlib of Kotlin is just bigger.


Garbage collector?


Reference counting in case of K/N.
Considering that Rust have almost no runtime and kotlin does, the difference of about 300k seems very small.