s

    Sean Najera

    2 years ago
    I just created a kotlin multiplatform library for android, ios and Javascript which uses the Ktor client for all networking. These are my dependencies for the javascript library
    // MPP - JS & common dependencies
    
        sourceSets["commonMain"].dependencies {
            implementation(kotlin("stdlib-common", Versions.KOTLIN))
            implementation(Deps.Ktor.COMMON_CORE)
            implementation(Deps.Ktor.COMMON_JSON)
            implementation(Deps.Coroutines.COMMON)
            implementation(Deps.MP_SETTINGS)
            implementation(Deps.Ktor.COMMON_SERIALIZER)
            implementation(Deps.Serialization.COMMON)
            implementation(Deps.Stately.COMMON)
            implementation(Deps.Stately.CONCURRENCY)
        }    
    
        sourceSets["jsMain"].dependencies {
            implementation((kotlin("stdlib-js", Versions.KOTLIN)))
            implementation(Deps.Ktor.JS_CORE)
            implementation(Deps.Ktor.JS_JSON)
            implementation(Deps.Coroutines.JS)
            implementation(Deps.Ktor.JS_SERIALIZER)
            implementation(Deps.Serialization.JS)
        }
    My goal is to write the repository layer as a library for the three platforms which can use it to request proprietary data, similar to Firebase Realtime database. But when I import the JS library into the Jetbrains starter React app my javascript binary is 27MiB for dev and 1MiB for prod distributions. Should I expect ktor & coroutines JS libraries to be that heavy for a JS library? Or am I doing something wrong?
    Robert Jaros

    Robert Jaros

    2 years ago
    You can check your
    build/js/packages/[project]/kotlin-dce
    directory - there you will find all kotlin js files used by your project (already processed by DCE). You can compare sizes of different libs.
    s

    Sean Najera

    2 years ago
    thanks again
    Robert Jaros

    Robert Jaros

    2 years ago
    Those files are used by webpack, combined with npm JS dependencies, bundled and once again minified with Terser plugin. Your ~1MB is the result.
    Never used ktor client for JS, but for my projects e.g. coroutines-core.js is larger than the whole kotlin.js (stdlib).
    s

    Sean Najera

    2 years ago
    That’s unfortunate. It would be really nice to use coroutines as a unified architecture for asynchronous programming in common code. I guess I might just have to figure out a way to abstract it away for JS
    Robert Jaros

    Robert Jaros

    2 years ago
    My largest Kotlin/JS project is 3,2MB bundle size. And it's usable 😉 Fortunately after gzip it's only ~600KB 😉
    Jurriaan Mous

    Jurriaan Mous

    2 years ago
    Kotlin 1.4 is said to dramatically decrease JS bundle size. You could try the M3 release.
    s

    Sean Najera

    2 years ago
    Unfortunately, I have deps that are not 1.4 M3 compatible. But good to know, thank you
    Jurriaan Mous

    Jurriaan Mous

    2 years ago
    This image was shared at the 1.4 keynote to get an impression how big the improvement is.
    Robert Jaros

    Robert Jaros

    2 years ago
    From my tests the improvement is not as big as shown on slides (I'v got only about 30% reduction of the bundle size). It probably very much depends on your libraries.