Hi,
I’m a part of a FIRST Robotics Team using Kotlin to program our robot. The computational resources that are available in this environment are nowhere near the level that modern computers have, and I’d like some advice with. For our 2019 season, our team, and several others, used a compile-time units wrapper that allowed for typesafe dimensional analysis throughout our code (Adding together different quantities was disallowed at compile time, rather than producing garbage results at runtime, for example). One of the problems that was faced is the overhead caused by instantiating large amounts of objects that are only in use for a little bit of time. The team that originally created this system ended up dialing back how much the wrappers were used because of the performance overhead they were seeing. As a part of that I’ve been trying to find a way to make this better, however all my attempts have been dead ends.
The key issue that I’ve found with this is that the wrapper classes only have to exist at compile time. Once compiled the wrappers are useless, as the code had to be validated through our rules during type checking. As such my first idea was to try to use inline classes, but that quickly hit a wall due to garbage bytecode that was produced for certain operations. That is disregarding the fact that inline classes keep a wrapper around just in case, and I have no control over whether the unboxed or boxed type is used.
Once typechecked, the only thing that the library we’re using does is provide ways to convert between units, which is just division between the contained Double
and some other constant, so in a perfect world, the types would be able to be completely erased and replaced with doubles and some mul/div operations to convert between units. However I can’t think of a way to do that in Kotlin as it is today
Is there anything coming in the future that would allow that? Is this something that a compiler plugin would solve? I love Kotlin but in niche usecases like this, I feel as though it does come up a bit short