is it just me or does kotlinx.serializable on a Ko...
# javascript
j
is it just me or does kotlinx.serializable on a Kotlin class really makes the generated JS explode in size? without Kotlin serialization
Copy code
-rw-rw-r-- 1 vlad vlad  79K Jul 18 10:22 register.e2a243ea.js
with serialization
Copy code
-rw-rw-r-- 1 vlad vlad  349K Jul 18 09:21 register.6e5afb3d.js
might be more efficient to just use JS's stringify on the frontend and gson / jackson on the backend removing serialization completely, all the annotations and and imports and it drops down to 17K, so that's a 300kB+ penalty for using serialization
r
Last year I've filled an issue about it - https://github.com/Kotlin/kotlinx.serialization/issues/430, but it was closed a few days ago without resolution.
Unfortunately you have to be careful adding Kotlin libraries (serialization, coroutines, ktor) to Kotlin/JS project, because most of these libs are filled with functionalities, which is very cool on the JVM, but makes JS bundle very large 😕
j
i've discovered that now as well, couldn't understand why my app size just blew up from a nice 17kB to 349kB have a logged a bug just before seeing your post https://youtrack.jetbrains.com/issue/KT-40428
r
And it's not only about JB libs. Most 3-party multiplatform libs have the same problem. No one really cares about JS size ;-)
j
JS size is super important, if KotlinJS wasn't this amazing to work with, i would have written this by hand in JS / TS
i guess i'll be doing that for serialization now before i go too deep into the rabbit hole of depending on kserialization
same issue with coroutines and ktor, i decided to replace ktor with window.fetch, it's literally a one-liner to POST instead of the whole ktor and instead of coroutines, i just decided to use the callbacks, they're not that terrible in KotlinJS
r
In my KVision I often preferred to implement the functionality myself or use a well-optimized JS library, than to use functions from the available Kotlin libraries.
exactly my point
j
the main issue is that the data class generates something which serializes to __firstName_3: "blah" instead of firstName: "blah" @JsName doesn't seem to help in this case
maybe i should replace @JsExport with @JsName on all the fields, not sure if they are clashing
r
I hope it will be better with 1.4.
And in the future I hope the libraries will be better optimized for DCE.
j
i'm on 1.4 M3
doesn't seem like the DCE is doing anything to these external libraries, looking at the generated JS, there are tons of things in that file for serialization that doesn't look like it's being used
running an external JS minifier, the 700kB JS file gets down to 349kB, but there's still a bunch of stuff in there that IMO should have been removed by DCE
for an enormous enterprise app, that 349kB is probably fine, for a simple page with a contact form on it that is serializing a data class with two strings and a boolean, i don't want it to be more than maybe 15kB
t
No one really cares about JS size 😉
ES6 and root/global export required to unblock webpack optimizations
j
that last comment by Sébastien Deleuze, amen to that currently using lit-html and have to glue it on via TypeScript