How do you measure size impact of a Kotlin depende...
# javascript
s
How do you measure size impact of a Kotlin dependency on Kotlin/JS library release executable? • One option is to build a JS executable via
jsBrowserDistribution
where we get a fat
.js
file. Here is the output for this for my sample project
Copy code
shared.js => 122KB
shared.js.map => 49KB
• Another option is to ship library as an NPM module. For example @Big Chungus’s plugin task `packJsNpmPublication`provides output like this for same sample project
Copy code
npm notice === Tarball Contents === 
npm notice 316.8kB Kmp_Library-shared.js    
npm notice 117B    package.json             
npm notice 71.7kB  Kmp_Library-shared.js.map
npm notice 715B    Kmp_Library-shared.d.ts  
npm notice === Tarball Details === 
npm notice name:          shared                                  
npm notice version:       0.1.0                                   
npm notice filename:      shared-0.1.0.tgz                        
npm notice package size:  74.5 kB                                 
npm notice unpacked size: 389.3 kB
# Which number to believe from both options? Now for example if I want to add
kotlinx.datetime
dependency in my project I want to measure how much size impact it would do to my library user.
b
The fat js file in most cases. Although some js libraries ship non js resources as well, in which case packed js publication is a better representation.
s
@Big Chungus but if someone is shipping an NPM module (without any non js resources) then what does above sizes implicate that are shown as result of ``packJsNpmPublication` command ? Or we need to every time go back to
jsBrowserDistribution
just to measure the accurate size?
b
packJsNpmPublication
depends on
jsProductionExecutable
and adds some metadata to it (like package.json, bundledDependencies, shrinkwrap.json). 99% of the time I personally would look at
jsProductionExecutable
output when comparing sizes.
s
but that (output of jsProductionExecutable) would be
unminified
size right? For minified I guess we would still look at
jsBrowserDistribution
output size?
b
No, production executable is already minified. jsCompileKotlin is one producing unminified output
jsBrowserDistribution
just collects your resources and js output
s
but then shouldn't
jsBrowserDistribution
and
jsProductionExecutable
sizes match closely? I get this output from
jsProductionExecutable
size of the
shared.js
in screenshot is
1.6MB
but the size of fat
.js
file i get via
jsBrowserDistribution
is
800KB
.
b
Hmm, you might be onto something here. Not sure what's going on tbh.
s
Hmm. It's fresh library with one method for testing so hopefully nothing wrong on my side. But yeah thanks for the help. I'll keep looking
b
Initial size overhead for just using kotlin.js is quite substantial. I think the sizes you currently have are to be expected.
s
Yeah makes sense. I was more confused from size mismatch/gap of around 800KB between
jsProductionExecutable
and
jsBrowserDistribution
outputs
b
I think one is post dce, while another is post dce + post webpack
s
Interesting