Compiler optimizations

I’m trying to use functional style programming - something like HTMLBuilder example. The code looks great and funny, but 5kB of code is compiled to 31 classes of 50kB. Do you have some plans for optimization lambda expressions compilation in future versions?

You can optimise your code by using inline, see https://kotlinlang.org/docs/reference/inline-functions.html

Furthermore it would be interesting to know what your expectations are. How does your code compare to for instance a pure Java solution?

Inlining can help for certain kinds of code.

To reduce on-disk size and class count, the Kotlin compiler could use the same infrastructure as the Java 8 compiler does (invokedynamic) to spin the classes at runtime. I believe the JB team are planning on adding the ability to target Java 8 in future. Of course, is 45kb of code on disk really a big deal? Even Java 8’s approach has the same amount of code and classes in memory at runtime. It’s not really more efficient except in terms of download size (and for that, check pack2000).

Thank you for quick answer

The thing is our main product is an enterprise application that is already big engough to take care of the compiled code size.
OOP style kotlin class is complied to 1-2 .class files with almost the same size as the souce code is and it’s just great. But when I start using lambdas - compiler generates a lot of artefacts like HtmlBuilderKt$main$result$1$2$6.class.
As result - application size is growing for 5-10 times and it’s a real showstopper.