Skip to content

Feature: Erased-generics mode to eliminate monomorphization overhead #30

Description

@AnuthaDev

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)

Activity

  1. IntegralPilot commented on Jul 13, 2026

    @IntegralPilot
    Owner

    Thank you so much for this! I will have a closer look into it when I'm more free to analyse a complex change like this, on the surface though I think erasure would actually be really useful (and had it in my own internal roadmap in my head), so I am really grateful that you helped help out and handle this for me.

  2. added
    A-lower1Involving the 1st lowering pass (MIR -> OOMIR)
    A-lower2Involving the 2nd lowering pass (OOMIR -> JVM)
    C-FeatureNew functionality is requested
    S-Pending DevelopmentWell defined issue with a MRE (if applicable) waiting for development work to begin on it.
    on Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lower1Involving the 1st lowering pass (MIR -> OOMIR)A-lower2Involving the 2nd lowering pass (OOMIR -> JVM)C-FeatureNew functionality is requestedS-Pending DevelopmentWell defined issue with a MRE (if applicable) waiting for development work to begin on it.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions