pulyaevskiy / firebase-functions-interop

Firebase Functions Interop Library for Dart.
BSD 3-Clause "New" or "Revised" License
191 stars 52 forks source link

Build with/without the `minify` flag produces almost the same uploaded code size #40

Closed kostaa closed 5 years ago

kostaa commented 5 years ago

I have noticed that running the build with the minify flag does not seem to make much difference when it comes to the size of the actual code that is uploaded to the server.

Without the flag I get:

Compiled 9,615,889 characters Dart to 1,133,281 characters JavaScript in 10.4 seconds ... functions: packaged functions (67.32 MB) for uploading

and with the flag:

Compiled 9,615,392 characters Dart to 429,438 characters JavaScript in 10.9 seconds ... functions: packaged functions (67.12 MB) for uploading

Since the minified code is less then half of the non-minified I would expect much bigger reduction in the code that is uploaded as well.

pulyaevskiy commented 5 years ago

It is likely because Firebase bundles all dependencies in the same archive. And most of those dependencies are regular Node.js packages, which we do not control from Dart.

Building Dart code only affects your final main.dart.js file (or whatever name you gave it) and you should only compare this file.

Based on your logs it does go down by more than 60% it looks like.

kostaa commented 5 years ago

Ok that makes sense but in that case there is not much point in minifying I guess since the bulk of the code will always be in the libraries. Unless there is a way to minify the Node.js packages as well.

pulyaevskiy commented 5 years ago

Yeah, I'm not sure if Firebase provides any tool to minify everything.

But it's really not that critical for server-side code. Minification is important for browser apps as far as I understand, since it improves latency. Server-code is loaded in memory and sits there.

kostaa commented 5 years ago

That is true. Unless you have to debug your code by constantly re-compiling and re-deploying it to the server which I have been doing over the last seven days or so :-) But I am pretty much done now.

pulyaevskiy commented 5 years ago

You can at least write tests for you own code which does not depend on FirebaseFunctions.

I usually do one of two things:

  1. Write a regular Dart test for any code that can be tested without depending on cloud stuff. I mark those tests with @TestOn('node') and just run them with pub run test.

  2. Create a simple console app which invokes more complex logic, so I can test it without having to re-deploy every time I change something (I only need to re-build the script, but that's tolerable).

This way I can catch 99% of errors before having to deploy with Firebase tool.

pulyaevskiy commented 5 years ago

I should probably write a blog post or something about this with more details. :)

kostaa commented 5 years ago

This was sort of one off a proof of concept if you like. Going forward I will definitely need to adopt a bit more structured approach. So any thoughts you can share will be most welcome.