Derek Peirce
02/10/2020, 2:25 AMequals
or hashCode
or toString
implementation that uses fields based on their annotations or types, and to write easily understood serialization and deserialization formats.
Another example. If properties are more aggressively inlined, it would also simplify existing code that uses properties.
Consider this use of map delegation:
class MapExample(
map: Map<String, String>
) {
val x by map
}
When the by
is inlined, it becomes (effectively):
val x: String get() = map.getOrImplicitDefault(MapExample::x.name)
The decompiled class contains an entire KPropertyObject
that is used only for its name. Suppose that this name access were inlined, because the compiler knows that the name of x
is “x”:
val x: String get() = map.getOrImplicitDefault("x")
Now the overhead of involving properties is entirely eliminated.
As I work on mobile code where reductions in bytecode size and execution time are top priorities, I would like to have property-inlining features like these to be able to use reflection-like features without their large overhead (We’ve eliminated many uses of by
because of the unnecessary KProperty
fields). Would these be feasible for the language, and how useful would they be to you?Hanno
02/10/2020, 6:43 PMDerek Peirce
02/11/2020, 3:07 AM