Hi everyone, I'm investigating the Kotlin MPP tech...
# javascript
a
Hi everyone, I'm investigating the Kotlin MPP technology for my company to see if it could be a good solution to develop library for our Android, iOS and web (front) Application. I have done some test using simple things like serialization and injection and after a few adaptation, it works on all 3 platforms. I have only one problem on the web side: The size of the library! My project count less than 250 lines of code and use juste one external library (
kotlinx.serialization
) and the generate bundle, once imported, is over 280KB (I have used
source-map-explorer
to analyze it). Am I missing something ? a configuration or something. I have read some stuff around DCE but it seems to be already active in my project.
j
Are you using the IR backend?
You should have something like the following in your build.gradle:
Copy code
kotlin {
    js(IR) { // <- New, more optimised compiler
      // Js config...
    }
}
r
280KB is not very much. Unfortunately you will easily go over 1MB (or even more) if you use more mpp libraries. It's a known issue with Kotin/JS and we all hope IR will make things better.
j
280kb is probably acceptable but still not great. Code splitting and other general good best practices might help you keep this down
a
Thanks for your replies. Yes I'm using IR, here is my config:
Copy code
js(IR) {
        browser {
            webpackTask {
                mode = org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Mode.PRODUCTION
                sourceMaps = false
            }
        }
        binaries.executable()
    }
When I compare to react with his ~30KB, I think that 280 is huge, no ? By code splitting you mean using specific code by platform and not all in common code ?
r
Of course it's huge when you compare it to React (try comparing to Svelte! 🙂). But for a moment that's the best you can get from Kotlin/JS.
👍 1
n
My web projects using Kotlin tend to cost me around 1MB filesize overhead compared to if I used plain JS or TypeScript. It's not just the runtime overhead but the output just tends to be larger. For a lot of projects this is acceptable (web applications, enterprise, games), but for small to medium projects it's a deal breaker for me.
👍 1
a
Actually, I think that if you remove serialization, it will be like 50-70 kB. But coroutines and other libraries are heavy indeed.
a
Yes indeed, and more than that, without serialization i'm arrount 10kb. So to make it works I need to reimplement it by my self or inject it ?
a
It depends on what do you need from serialization
c
@Anthony Pages did you just share models and business logic by the use of an mpp module or did you wrote the react frontend with kotlin as well. I'm currently looking for a good source (article, tutorial, example project, what ever) that show cases how to use models from a mpp module in a typescript react app. Can someone recommend any source?
a
I'm sharing, the aim is to refacto some of our actual feature with Kotlin MPP and put them into our living applications (iOS, Android, Web). I started to work with KMPP 3-4months ago and I just use the kotlin documentation and used google to solve little issues. From now, I have no code to share as it may contain some sensitive data but if make a sample or so, I would not forget to post and link it to you 🙂