I actual have DCE enabled. And I just tested it my...
# javascript
f
I actual have DCE enabled. And I just tested it my es6 to es5 is not that much bigger still approximately 9x smaller
b
Could you please share your code generated from Kotlin and ES6?
f
I will upload the projects later today and post here again
b
thanks!
f
@bashor I've uploaded the source code of both code basis (please note that the kotlin implementation is slightly less advanced then the JS version) and also uploaded the compiled files of both projects. I also already started using the RC of Kotlin 1.3 but the size was not much different compared to Kotlin 1.2. JS: Source=https://gitlab.com/fkrauthan/screeps-bot-js Compiled=https://www.dropbox.com/s/8lo59gjvnkjiyve/screeps-ai-js.zip?dl=0 Kotlin: Source=https://gitlab.com/fkrauthan/screeps-bot-kotlin Compiled=https://www.dropbox.com/s/0nvg1piymguukzs/screeps-ai-kotlin.zip?dl=0 Let me know if you have any questions. The code is for the Programming game screep (https://docs.screeps.com) thats why you see the interfacing with some Javascript objects and why I need to write and read information from javascript into data objects etc.
b
Thank you for the links! I can promise big improvements in a short time, but now we actively working on compiler backend it will be much better, stay tuned! Anyway, we’ll investigate your case and try to help you.
@fkrauthan maybe you can replace
kotlinx.serialization
with some ad-hoc lightweight implementation?
f
@bashor Well the only solution would be to duplicate all my shared entities which is obviously from a developers point of view quiet the pain. I would love if the KotlinJS compiler can provide a simple json to data class and data class to json converter so I can remove
kotlinx.serialization
as I don't need all the fancy stuff it provides
b
Please try to replace your deserializing part with something like:
DynamicObjectParser().parse<YourDataType>(JSON.parse(s))
, I think it allow DCE to remove more.
But note, it will not work right with
Long
f
I'll give that a try and report back
not sure if there is a board for feature requests but a .toJS() and a static fromJS on data classes could be very handy for Javascript
b
what should be result of toJS?
and input of fromJS
f
Pretty much convert it to a normal JS Object and convert a normal JS object to a data class (similar if I would write a external interface for my data class and write manual attribute copy methods from my data class to external interface field and back)
A simple way to write and store JS objects in browser APIs or third party libraries is a big part of JS development. But in Kotlin I obviously would like to work with class and data class
Hmm changing it did not do anything to the compiled size
I changed the code to
Copy code
var CreepMemory.task: Task?
        get() {
            val internal = this.asDynamic()._task
            return if (internal == null) null else Tasks.create(DynamicObjectParser().parse(internal))
        }
        set(value) {
            val stringyfied = if (value == null) null else kotlin.js.JSON.parse(JSON.stringify(value))
            this.asDynamic()._task = stringyfied
        }
b
kotlin.js.JSON.parse(JSON.stringify(value))
why do you reparse it back?
f
So that I am able to store it as an actual JS Object. I don't parse it back with kotlinx serializer but rather with javascript
JSON.parse