We can skip monomorphization overhead during compile time by using invokedynamic. This would lead to smaller JAR file sizes and should also improve compilation speed in big crates with a lot of generics.
An agent driven crude and partial implementation is in this branch: https://github.com/AnuthaDev/rustc_codegen_jvm/tree/generic-erasure
The code and markdown files should serve as a good starting point for a proper implementation.
Here are some statistics from that branch, tested on a Macbook M4 pro:
Compilation Time
erased_bench crate:
| Mode |
Avg (s) |
Min (s) |
Max (s) |
| Native rustc (debug) |
0.476 |
0.47 |
0.48 |
| Native rustc (release) |
0.474 |
0.47 |
0.55 |
| JVM Mono (debug) |
0.219 |
0.21 |
0.28 |
| JVM Erased (debug) |
0.200 |
0.19 |
0.21 |
Binary/Jar Size
| Mode |
erased_bench |
| Native (debug) |
503,296 bytes |
| Native (release) |
430,400 bytes |
| JVM Mono |
43,363 bytes (52 classes) |
| JVM Erased |
25,877 bytes (24 classes) |
We can skip monomorphization overhead during compile time by using
invokedynamic. This would lead to smaller JAR file sizes and should also improve compilation speed in big crates with a lot of generics.An agent driven crude and partial implementation is in this branch: https://github.com/AnuthaDev/rustc_codegen_jvm/tree/generic-erasure
The code and markdown files should serve as a good starting point for a proper implementation.
Here are some statistics from that branch, tested on a Macbook M4 pro:
Compilation Time
erased_benchcrate:Binary/Jar Size
erased_bench