Generate Codec instances at runtime for records

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Codecs, Performance
    • None
    • None
    • Java Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      Using the Class-File API introduced in Java 24 (or ASM if we want to support Java 17/21), generate Codec instances for records at runtime. This moves reflection out of the critical path and delivers performance on par with a hand-written Codec.

      Motivation

      Who is the affected end user?

      Developers looking to drive down encoding/decoding latency. 

      How does this affect the end user?

      It improves encoding/decoding performance without adding additional build steps, which would be required with alternative designs (e.g. source code generation using Gradle/Maven plugins)

      Is this issue urgent?

      No, it's not urgent.  And if we use the Class-File API it will only help applications running on Java 24+, which at this point isn't a large cohort.  However, we should see more uptake of Java 25, which is an LTS release.

      What are the risks?

      Generating class files directly comes with inherent risks, as you don't have the Java compiler to protect you from creating invalid class files (e.g. failure to link, failure to pass the classfile verifier). 

      There's a POC here: https://github.com/jyemin/bson-record-codegen

            Assignee:
            Unassigned
            Reporter:
            Jeffrey Yemin
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: